#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  if (b == 0) {
    return 1;
  }
  if (b & 1) {
    return a * power(a * a, b / 2);
  }
  return power(a * a, b / 2);
}
void solve() {
  int n;
  cin >> n;
  string s, t;
  getline(cin >> ws, s);
  getline(cin >> ws, t);
  int state[2] = {0};
  int ss[2] = {0}, tt[2] = {0};
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      ss[1]++;
    } else {
      ss[0]++;
    }
    if (t[i] == '1') {
      tt[1]++;
    } else {
      tt[0]++;
    }
  }
  int ans = 0;
  if (ss[0] == tt[0] && ss[1] == tt[1]) {
    for (int i = 0; i < n; i++) {
      if (s[i] != t[i]) {
        if (s[i] == '0') {
          if (state[1] > 0) {
            state[1]--;
            state[0]++;
          } else {
            state[0]++;
            ans = max(ans, state[0]);
          }
        } else {
          if (state[0] > 0) {
            state[0]--;
            state[1]++;
          } else {
            state[1]++;
            ans = max(ans, state[1]);
          }
        }
      }
    }
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
