#include<iostream>
using namespace std;
int main()
{int a,b,i,x,k,y,p,d,c,ok;
cin>>a>>b;
c=0;
for(i=a;i<=b;i++)
{ y=0;
p=1;
x=i;
k=0;
while(x!=0)
{
y=y+p*(x%2);
x=x/2;
p=p*10;
k++;
}
ok=0;
for(d=2;d<=k/2;d++)
if(k%d==0)ok=1;
if (k!=2 && ok==0) c++;
}
cout<<c;
return0;
}