#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, k;
string s, t;
int arr[N];
int get(int x) {
  int curr = 0, mx = 0;
  for (int i = 1; i <= n; i++) {
    curr += x * arr[i];
    mx = max(mx, curr);
    if (curr < 0) curr = 0;
  }
  return mx;
}
void test_case() {
  cin >> n >> s >> t;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] != t[i - 1]) {
      if (s[i - 1] == '1')
        arr[i] = -1;
      else
        arr[i] = 1;
    }
    sum += arr[i];
  }
  if (sum != 0) {
    cout << -1;
    return;
  }
  int ans = max(get(1), get(-1));
  cout << ans;
  cout << "\n";
  return;
}
void solve() {
  int t;
  t = 1;
  for (int nr = 1; nr <= t; nr++) {
    test_case();
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
