#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  string s[2];
  int n;
  cin >> n >> s[0] >> s[1];
  int cnt[2][2];
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) cnt[i][j] = 0;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < n; j++) cnt[i][s[i][j] - '0']++;
  if ((cnt[0][0] != cnt[1][0]) || (cnt[1][1] != cnt[0][1]))
    return cout << "-1\n", 0;
  vector<int> vec;
  for (int i = 0; i < n; i++)
    if (s[0][i] == '1' && s[1][i] == '0')
      vec.push_back(1);
    else if (s[0][i] == '0' && s[1][i] == '1')
      vec.push_back(-1);
  n = vec.size();
  int ans = 0, sum = 0, mn = 0;
  for (int j = 0; j < 2; j++) {
    sum = 0, mn = 0;
    for (int i = 0; i < n; i++) {
      sum += vec[i];
      mn = min(mn, sum);
      ans = max(ans, sum - mn);
      vec[i] *= -1;
    }
  }
  cout << ans << '\n';
  return 0;
}
