#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  string s, t;
  vector<int> a(n + 1);
  cin >> s >> t;
  for (int i = 0; i < n; ++i) {
    if (s[i] != t[i]) {
      if (s[i] == '1') {
        a[i] = 1;
      } else {
        a[i] = -1;
      }
    } else {
      a[i] = 0;
    }
  }
  int sum = 0;
  int ma = 0, mi = (int)1e9 + 7;
  for (int i = 0; i < n; ++i) {
    sum += a[i];
    ma = max(sum, ma);
    mi = min(mi, sum);
  }
  if (sum != 0) {
    cout << "-1" << endl;
    return;
  }
  cout << ma - mi << endl;
}
int main() {
  { solve(); }
}
