#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

template <size_t N>
class GreaterThan { 
public:
   bool operator() (const std::bitset<N> &lhs, const std::bitset<N> &rhs) const 
   { 
      size_t i = N;
      while ( i > 0 ) {
         if ( lhs[i-1] == rhs[i-1] ) {
            i--;
         } else if ( lhs[i-1] > rhs[i-1] ) {
            return true;
         } else {
            return false;
         }
      }
      return false;
   } 
}; 
void solve(long long A, long long B){
  vector<vector<ll>> m(B-A+1,vector<ll>(B-A+1));
  For(i,B-A+1){
    FOR(j,i+1,B-A+1){
      m[i][j]=m[j][i]=gcd(i+A,j+A);
    }
  }
  vector<ll> allnum(B-A+1);
  bitset<73> start;
  For(i,B-A+1){
    start[i]=true;
    allnum[i]=i+A;
  }
  map<bitset<73>,ll,GreaterThan<73>> q;
  q[start]=1;
  auto addmap = [](map<bitset<73>, ll,GreaterThan<73>> &q, const bitset<73> &bs, ll x) {
    if(q.count(bs))
    {
      q[bs]+=x;
    }
    else
    {
      q[bs]=x;
    }
  };
  for (auto [primes, cnt] : q)
  {
    if (primes.none())
    {
      continue;
    }
    ll i = 0;
    for (i = 0; i < 73; i++)
    {
      if (primes[i])
        break;
    }
    auto newprimes = primes;
    newprimes[i] = false;
    addmap(q, newprimes, cnt);
    For(j, B - A + 1)
    {
      if (m[i][j] != 1)
      {
        newprimes[j] = false;
      }
    }
    addmap(q, newprimes, cnt);
  }
  bitset<73> clean;
  cout<<q[clean]<<endl;
}

int main(){
  cout<<setprecision(1000);
  long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
  solve(A, B);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<unsigned char>s(19,'a');
  for(int i=0;;i++){
    cin>>s.at(i);
    if(s.at(i)=='a') break;
  }
  for(int i=18;;i--){
    if(s.at(i)=='a') s.pop_back();
    else break;
  }
  vector<int>v(s.size());
  for(int i=0;i<s.size();i++) v.at(i)=(int)s.at(i)-48;
  vector<int>v3(3,0);
  for(int i=0;i<v.size();i++){
    if(v.at(i)%3==0) v3.at(0)++;
    else if(v.at(i)%3==1) v3.at(1)++;
    else v3.at(2)++;
  }
  int a,b;
  a=v3.at(1)*1;
  b=v3.at(2)*2;
  if((a+b)%3==0) cout<<0<<endl;
  else{
    if((a+b)%3==1&&v3.at(1)>0&&v.size()>1) cout<<1<<endl;
    else{
      if((a+b)%3==2&&v3.at(2)>0&&v.size()>1) cout<<1<<endl;
      else{
        if((a+b)%3==2&&v3.at(2)==0&&v3.at(1)>=2&&v.size()>2) cout<<2<<endl;
        else{
          if((a+b)%3==1&&v3.at(1)==0){
            for(int i=1;i<=v3.at(2);i++)
              if((a+b-i*2)%3==0&&v.size()>i){
                cout<<i<<endl;
                return 0;
              }
            cout<<-1<<endl;
          }
          else cout<<-1<<endl;
        }
      }
    }
  }
}