#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define md
#define ll long long
#define inf (int) 1e9
#define eps 1e-8
#define N 1000100
using namespace std;
ll q[N];
bool tag[N];
ll L,R,ans=0;
int w=0;
bool cmp(ll a,ll b) {return a>b;}
ll gcd (ll a,ll b) { return b==0?a:gcd(b,a%b);}
void dfs_86(ll x)
{
if (x>R) return;
if (x) q[++w]=x;
dfs_86(x*10+6); dfs_86(x*10+8);
}
void dfs(int pos,int dep,ll lcm)
{
if (pos>w) return;
dfs(pos+1,dep,lcm);
if (tag[pos]) return;
lcm*=(q[pos]/gcd(lcm,q[pos]));
if ((lcm<=0)||lcm>R) return;
dep++;
if (dep&1) ans+=R/lcm-(L-1)/lcm;
else ans-=R/lcm-(L-1)/lcm;
dfs(pos+1,dep,lcm);
}
int main()
{
scanf("%lld%lld",&L,&R);
dfs_86(0);
sort(q+1,q+w+1,cmp);
for (int i=1;i<=w;i++)
for (int j=i+1;j<=w;j++)
if (q[i]%q[j]==0) { tag[i]=1; break;}
dfs(1,0,1);
printf("%lld\n",ans);
return 0;
}