#include <algorithm>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath>
#include <cstdlib> // abs(int)
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

#define roundup(n, d) (((n) + ((d)-1)) / (d))
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define v_in(v)        \
    for (auto&& i : v) \
    cin >> i
#define vv_in(vv) rep(I, (long long)vv.size()) for (auto&& J : vv[I]) cin >> J
#define FAST_IO                  \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(), v.end()
#define printvar(x) cout << #x << ":" << x << endl

#define PI 3.14159265358979323846

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;

int main(void) {
    ll n, x;
    cin >> n >> x;
    ll x100 = x * 100;

    vvll in(n, vll(2));
    vv_in(in);

    ll sum = 0;
    rep(i, n) {
        sum += in[i][0] * in[i][1];
        if (sum > x100) {
            cout << i + 1 << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double; 
const string FILENAME = "input";


int n;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//read(FILENAME);
	cin >> n;
	string s, t;
	cin >> s >> t;
	int cnt = 0, cnt1 = 0;
	for (auto x: s) {
		if (x == '1') {
			cnt++;
		}
	}
	for (auto y: t) {
		if (y == '1') {
			cnt1++;
		}
	}
	if (cnt < cnt1) {
		cout << -1 << '\n';
		return 0;
	}
	if (cnt % 2 != cnt1 % 2) {
		cout << -1 << '\n';
		return 0;
	}
	vector<int> st;
	for (int i = 0; i < n; i++) {
		if (t[i] == '1') {
			st.pb(i);
		}
	}
	vector<int> st1;
	for (int i = 0; i < n; i++) {
		if (s[i] == '1') {
			st1.pb(i);
		}
	}
	int uk = 0;
	ll ans = 0;
	for (auto x: st) {
		while (true) {
			if (uk >= sz(st1)) {
				cout << -1 << '\n';
				exit(0);
			}
			if (st1[uk] < x) {
				if (uk + 1 == sz(st1)) {
					cout << -1 << '\n';
					exit(0);
				}
				ans += st1[uk + 1] - st1[uk];
				uk+= 2;
			} else {
				ans += st1[uk] - x;
				uk++;
				break;
			}
		}
	}
	if (uk < sz(st1)) {
		for (int j = uk; j < sz(st1); j += 2) {
			ans += st1[j + 1] - st1[j];
		}
	}
	cout << ans << '\n';
}	

