#include <bits/stdc++.h>
using namespace std;
const long long int MOD = (long long int)1e9 + 7;
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
    b = b >> 1;
  }
  return res % MOD;
}
long long int kad(vector<long long int> &a) {
  if (a.size() == 0) {
    return 0;
  }
  long long int ans = 0;
  long long int temp = 0;
  for (long long int i = 0; i < a.size(); i++) {
    temp += a[i];
    if (temp < 0) {
      temp = 0;
    }
    ans = max(ans, temp);
  }
  return ans;
}
void solve(long long int testnum) {
  long long int n;
  cin >> n;
  string s, t;
  cin >> s;
  cin >> t;
  vector<long long int> pcs, pcb;
  long long int cnt = 0;
  for (long long int i = 0; i < n; i++) {
    if (s[i] == '0' && t[i] == '1') {
      pcs.push_back(1);
      pcb.push_back(-1);
      cnt++;
    } else if (s[i] == '1' && t[i] == '0') {
      pcs.push_back(-1);
      pcb.push_back(1);
      cnt--;
    }
  }
  if (cnt != 0) {
    cout << "-1\n";
    return;
  }
  if (pcs.size() == 0) {
    cout << "0\n";
    return;
  }
  long long int ans = max(kad(pcs), kad(pcb));
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  for (long long int i = 1; i <= t; i++) {
    solve(i);
  }
}
