#include <bits/stdc++.h>
using namespace std;
const long long LINF = (long long)1e18 + 47;
const int INF = 2 * 1e9 + 47;
const int MOD = 1e9 + 7;
const int modulo = 1e8;
const int nax = (int)1e6 + 10;
const double EPS = 1e-7;
int c[nax];
int n;
vector<int> vec;
int get(int x) {
  int mx = 0;
  int cur = 0;
  for (int i = (0); i < (vec.size()); i++) {
    if (x == vec[i])
      cur++;
    else
      cur--;
    mx = max(mx, cur);
    if (cur < 0) cur = 0;
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  string a, b;
  cin >> a >> b;
  for (int i = (0); i < (n); i++) {
    if (a[i] != b[i]) {
      if (a[i] == '1')
        c[i] = 1;
      else
        c[i] = -1;
    }
  }
  int cnt = 0;
  for (int i = (0); i < (n); i++) {
    if (c[i] == 1)
      cnt++;
    else if (c[i] == -1)
      cnt--;
  }
  if (cnt) {
    cout << -1 << '\n';
    return 0;
  }
  for (int i = (0); i < (n); i++) {
    if (c[i] != 0) {
      vec.push_back(c[i]);
    }
  }
  int ans = 0;
  for (int i = (0); i < (vec.size()); i++) {
    int j = i;
    while (j < vec.size() && vec[j] == vec[i]) {
      j++;
    }
    int len = j - i;
    ans = max(ans, len);
    i = j - 1;
  }
  cout << max(get(-1), get(1)) << '\n';
}
