#include <bits/stdc++.h>
using namespace std;
long long q, n, c, x, r, a1[2], a2[2], a[1000000][2], c0, c1;
string s1, s2;
bool b[1000001];
long long dfs(long long xf) {
  if (!b[xf]) return xf;
  return a[xf][s1[xf] - '0'] = dfs(a[xf][s1[xf] - '0']);
}
int main() {
  cin >> n;
  cin >> s1 >> s2;
  for (int i = 0; i < n; i++) {
    a1[s1[i] - '0']++;
    a2[s2[i] - '0']++;
  }
  if (a1[0] != a2[0]) {
    cout << -1;
    return 0;
  }
  c0 = n;
  c1 = n;
  for (int i = n - 1; i >= 0; i--) {
    a[i][0] = c0;
    a[i][1] = c1;
    if (s1[i] != s2[i]) {
      if (s1[i] - '0' == 0)
        c0 = i;
      else
        c1 = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (s1[i] != s2[i] && !b[i]) {
      c = (s1[i] - '0' + 1) % 2;
      x = i;
      while (x != n) {
        b[x] = 1;
        if (b[a[x][c]]) a[x][c] = dfs(a[x][c]);
        x = a[x][c];
        c = (c + 1) % 2;
      }
      r++;
    }
  }
  cout << r;
  return 0;
}
