#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O2")
#pragma GCC optimization("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int N = 1000005;
string S, T;
int n;
set<int> g[2];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n;
  cin >> S;
  cin >> T;
  int o1 = 0, o2 = 0;
  for (char c : S)
    if (c == '1') o1++;
  for (char c : T)
    if (c == '1') o2++;
  if (o1 != o2) {
    cout << "-1\n";
    return 0;
  }
  set<int> st;
  for (int i = 0; i < n; i++) {
    if (S[i] == T[i]) continue;
    if (S[i] == '0') {
      g[0].insert(i);
    } else {
      g[1].insert(i);
    }
    st.insert(i);
  }
  int moves = 0;
  while (st.size() > 0) {
    moves++;
    int pos = *st.begin();
    int id;
    if (g[0].find(pos) != g[0].end())
      id = 0;
    else
      id = 1;
    while (1) {
      st.erase(st.find(pos));
      g[id].erase(g[id].find(pos));
      id = (id + 1) % 2;
      auto it = g[id].upper_bound(pos);
      if (it == g[id].end()) break;
      pos = *it;
    }
  }
  cout << moves << "\n";
}
