#include <bits/stdc++.h>
using namespace std;
long long n;
string S, T;
set<long long> st[2];
long long solve() {
  long long ans = 0;
  while (!st[0].empty() && !st[1].empty()) {
    long long sta = *st[0].begin();
    long long tick = 0;
    long long root = 0;
    ans++;
    long long cnt = 0;
    if (*st[1].begin() < sta) {
      sta = *st[1].begin();
      tick = root = 1;
    }
    while (true) {
      st[tick].erase(sta);
      cnt++;
      tick ^= 1;
      auto iter = st[tick].upper_bound(sta);
      if (iter == st[tick].end()) {
        if (tick == root)
          break;
        else {
          if (cnt == 1) return -1;
          st[tick ^ 1].insert(sta);
          break;
        }
      } else
        sta = *iter;
    }
  }
  if (!st[0].empty() || !st[1].empty()) return -1;
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> S >> T;
  for (long long i = (long long)0; i <= (long long)n - 1; i++) {
    if (S[i] == T[i]) continue;
    if (S[i] == '0')
      st[0].insert(i);
    else
      st[1].insert(i);
  }
  cout << solve() << '\n';
}
