#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
using namespace std;

int c[500009], p[500009];;
vector<int> v;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	string s, t; cin >> s >> t;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] != t[i]) {
			p[i + 1] = 1;
			if (t[i + 1] == '0') t[i + 1] = '1';
			else t[i + 1] = '0';
		}
		if (s[i + 1] == '1') v.push_back(i + 1);
	}
	if (s[n - 1] != t[n - 1]) {
		cout << -1 << '\n';
		return 0;
	}
	long long ans = 0;
	int pi = 0, r = 0;
	for (int i = 1; i < n; i++) {
		while (pi < v.size() && v[pi] < i) pi++;
		r = (r + c[i]) % 2;
		if (r == p[i]) continue;
		if (pi >= v.size()) {
			cout << -1 << '\n';
			return 0;
		}
		c[v[pi] + 1]++;
		r = (r + 1) % 2;
		ans += v[pi] - i + 1;
		pi++;
	}
	cout << ans << '\n';
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N,M,T;
  cin >> N >> M >> T;
  
  vector<int> a(M);
  vector<int> b(M);
  for(int i = 0; i < M*2; i++) {
    if(i%2 == 0) {
      cin >> a.at(i/2);
    }else{
      cin >> b.at((i-1)/2);
    }
  }
  
  bool Ans = true;
  int B = N;
  int Time = 0;
  for(int i = 0; i < M; i++) {
    B -= (a.at(i)-Time);
    Time = a.at(i);
    if(B <= 0) Ans = false;
    B += (b.at(i)-Time);
    Time = b.at(i);
    if(N < B) B = N;
  }
  B -= (T-b.at(M-1));
  if(B <= 0) Ans = false;
  
  if(Ans) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}