#include<bits/stdc++.h>
#define mxn 500005
#define ll long long
using namespace std;
char str[mxn], t[mxn];
int a[mxn], b[mxn];
int main()
{
    int n;
    scanf("%d %s %s", &n, str+1, t+1);
    for(int i=1; i<=n; i++)
    a[i]= str[i]-'0', b[i]= t[i]-'0';
    ll res= 0;
    int lst;
    if(str[1]==t[1])lst= 2;
    else lst= 1;
    for(int i=2; i<=n; i++)
    {
        if(str[i]=='1')
        {
            if(lst<i)
            {
                res+= (i-lst);
                a[lst]^= 1;
                a[i]= 0;
                while(lst<=i)
                {
                    if(a[lst]==b[lst])lst++;
                    else break;
                }
            }
            else if(a[i]==b[i])lst++;
        }
        else if(lst==i && a[i]==b[i])lst++;
    }
    if(lst<=n)res= -1;
    printf("%lld\n", res);
    return 0;
}

#include <bits/stdc++.h>          
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

int main() {
    ll N, X; cin >> N >> X;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    vector<ll> S(N);
    repm(i,N-1,0) {
        S[i] = X / A[i];
        X %= A[i];
    }

    vector<vector<ll>> dp(N+1,vector<ll>(2));
    dp[0][0] = 1;
    rep(i,N) {
        rep(j,2) {
            ll x = S[i] + j;
            if (x==0) {
                dp[i+1][0] = dp[i][j];
                continue;
            }
            if (i<N-1) {
                dp[i+1][1] += dp[i][j];
                if (x==A[i+1]/A[i]) continue;
            }
            dp[i+1][0] += dp[i][j];
        }
    }

    ll ans = dp[N][0];
    Cout(ans);
}