#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n;
vector<int> v;
string a, b;
int go(int x) {
  int maxv = 0, curr = 0;
  for (int i = 0; i < (int)v.size(); i++) {
    curr += x * v[i];
    curr = max(curr, 0);
    maxv = max(maxv, curr);
  }
  return maxv;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a >> b;
  int s = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      if (a[i] == '1') {
        v.push_back(1);
        s += 1;
      } else {
        v.push_back(-1);
        s += -1;
      }
    }
  }
  if (s != 0) {
    cout << -1 << "\n";
    return 0;
  }
  int ans = max(go(1), go(-1));
  cout << ans << "\n";
  return 0;
}
