#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, i;
  cin >> n;
  string s, t;
  cin >> s >> t;
  long long c1, c2, c3, c4;
  c1 = c2 = c3 = c4 = 0;
  if (s.size() != t.size()) {
    cout << -1;
  } else {
    string ans;
    for (i = 0; i < s.size(); i++) {
      if (s[i] == '1')
        c1++;
      else
        c2++;
      if (t[i] == '1')
        c3++;
      else
        c4++;
      if (s[i] != t[i]) {
        ans.push_back(s[i]);
      }
    }
    if (c1 != c3 or c2 != c4) {
      cout << -1;
    } else {
      long long maxtill = 0;
      long long a0 = 0, a1 = 0;
      for (i = 0; i < ans.size(); i++) {
        if (!a1 and !a0) {
          if (ans[i] == '0')
            a1++;
          else
            a0++;
        } else {
          if (ans[i] == '0') {
            if (a0 > 0)
              a0--, a1++;
            else
              a1++;
          } else if (ans[i] == '1') {
            if (a1 > 0)
              a1--, a0++;
            else
              a0++;
          }
        }
      }
      cout << a0 + a1 << '\n';
    }
  }
}
