#include <bits/stdc++.h>

using namespace std;

namespace ftr {

vector<int> prime;

void run_sieve(int n) {
  assert((int) prime.size() == 0);
  prime = vector<int>(n, 1);
  prime[0] = prime[1] = 0;
  for (int i = 2; i < n; i++) {
    if (prime[i]) {
      for (int j = i + i; j < n; j += i) {
        prime[j] = 0;
      }
    }
  }
}

template <typename T>
vector<pair<T, int>> factorize(T x) {
  if (x <= 1) {
    return {};
  }
  vector<pair<T, int>> ret;
  for (T i = 2; i * i <= x; i++) {
    T t = x / i;
    if (i > t) break;
    if (x == t * i) {
      int cnt = 0;
      while (x % i == 0) {
        x /= i; 
        cnt++;
      }
      ret.emplace_back(i, cnt);
    }
  }
  if (x > 1) {
    ret.emplace_back(x, 1);
  }
  return ret;
}

} // namespace ftr   

int main() {  
  ios::sync_with_stdio(false);
  cin.tie(0);
  ftr::run_sieve(100);
  vector<int> primes;
  int val = 2;
  while ((int) primes.size() < 20) {  
    if (ftr::prime[val]) {
      primes.push_back(val);
    } 
    ++val;
  } 
  long long A, B;
  cin >> A >> B;
  const int N = (int) primes.size();
  vector<long long> dp(1 << N);
  dp[0] = 1;
  for (long long val = A; val <= B; val++) {  
    int bit = 0;
    for (int i = 0; i < N; i++) {
      if (val % primes[i] == 0) {
        bit |= (1 << i);
      }
    }
    for (int t = 0; t < (1 << N); t++) {
      if ((bit & t) == 0) {
        dp[bit ^ t] += dp[t];

      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < (1 << N); i++) {
    ans += dp[i];
  }
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

//begin of def

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define endl '\n'

using lli = long long int;
using ulli = unsigned long long int;
using Ld = long double;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
using pld = pair<Ld, Ld>;
#define X first
#define Y second

#define rep(I, S, E) for(int I = (S); I < (E); I++)
#define repq(I, S, E) for(int I = (S); I <= (E); I++)

#define pb push_back
#define epb emplace_back

#define ALL(X) X.begin(), X.end()

//end of def

int main(){
    fastio;
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    int az = 0, bz = 0;
    int ct = 0;
    rep(i, 0, n){
        if(b[i] == '0'){
            bz++;
        }
        if(a[i] == '0'){
            az++;
            ct += (az != bz || a[i] != b[i]);
        }
    }
    if(az != bz)
        cout << -1;
    else
        cout << ct;
    return 0;
}
