#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, i, count = 0, ans = 0, c0 = 0, c1 = 0;
  cin >> n;
  string s, t, st = "";
  cin >> s >> t;
  for (i = 0; i < n; i++) {
    if (s[i] != t[i]) {
      st += s[i];
      if (s[i] == '1')
        count++;
      else
        count--;
    }
  }
  if (count != 0)
    cout << -1;
  else if (st.length() == 0)
    cout << 0;
  else {
    ans = 0;
    for (i = 1; i < st.length(); i++) {
      if (st[i] == '1') {
        if (c0 > 0)
          c0--;
        else
          ans++;
        c1++;
      } else {
        if (c1 > 0)
          c1--;
        else
          ans++;
        c0++;
      }
    }
    cout << ans;
  }
  return 0;
}
