#include <bits/stdc++.h>
#pragma optimize("O3")
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 47;
const int base = 2e5 + 1;
const long long MAX = 1e6 + 1;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 5000 + 47;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  int sum = 0, mx = 0, mn = 0, res = 0;
  for (int i = (0); i < (n); ++i) {
    if (s[i] != t[i]) {
      if (s[i] == '1')
        sum++;
      else
        sum--;
      res = max(res, abs(sum - mn));
      res = max(res, abs(mx - sum));
      mx = max(mx, sum);
      mn = min(mn, sum);
    }
  }
  if (sum != 0)
    cout << -1;
  else
    cout << res;
  return 0;
}
