#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    string S,T; cin>>S>>T;
    queue<int> v1,v2;
    rep(i,N)if(S[i]=='1') v1.push(i);
    rep(i,N)if(T[i]=='1') v2.push(i);

    ll ans=0;
    {
        int t = (v2.empty()) ? N : v2.front();
        while(!v1.empty()){
            if (v1.front()<t){
                if (v1.size()<2){
                    cout<<"-1\n";
                    return 0;
                }
                int x = v1.front(); v1.pop();
                int y = v1.front(); v1.pop();
                ans+=y-x; 
            }else{
                int x = v1.front(); v1.pop();
                ans+=x-t;
                v2.pop();
                t = (v2.empty()) ? N : v2.front();
            }
        }
        if (!v2.empty()){
            cout<<"-1\n";
            return 0;
        }
    }
    cout<<ans<<"\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
template <class T>
bool chmax(T& a, const T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define FOR(i, l, r) for (int i = (l); i < (r); ++i)
#define RFOR(i, l, r) for (int i = (r)-1; (l) <= i; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<ll, ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = (1 << 30) - 1; // 1073741824 - 1
// static const ll INF = (1LL << 60) - 1;  // 4611686018427387904 - 1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, x;
    cin >> n >> x;

    int ans = 1;
    double total = 0;
    REP(i, n) {
        double v, p;
        cin >> v >> p;
        total += v * p;
        if (total > x * 100) {
            break;
        }
        ans++;
    }
    if (ans > n) {
        ans = -1;
    }
    COUT(ans);
    return 0;
}