#include<bits/stdc++.h>
#include<queue>
using namespace std;
int main () {
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  int s = 0;
  int t = 0;
  for (int i = N - 1; i >= 0; i --) {
    if (S[i] == '1') s ++;
    if (T[i] == '1') t ++;
    if (s < t) {
      cout << -1 << endl;
      return 0;
    }
  }
  if ((s - t) % 2 != 0) {
    cout << -1 << endl;
    return 0;
  }
  int sp = -1;
  queue<int>tp;
  long long ans = 0;
  for (int i = 0; i < N; i ++) {
    if (T[i] == '1') {
      tp.push(i);
    }
    if (S[i] == '1') {
      if (sp != -1) {
        ans += (long long)(i - sp);
        sp = -1;
      } else if (!tp.empty()) {
        ans += (long long)(i - tp.front());
        tp.pop();
      } else {
        sp = i;
      }
    }
    //cout << sp << ' ' << tp << ' ' << ans << endl;
  }
  cout << ans << endl;
}
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
void no(){
    cout << "-1";
    exit(0);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int N;
    string S, T;
    cin >> N >> S >> T;
    vector<int> s, t;
    for(int i = 0; i < N; i += 1) if(S[i] == '1') s.push_back(i); 
    for(int i = 0; i < N; i += 1) if(T[i] == '1') t.push_back(i);
    LL ans = 0;
    for(int i = 0, j = 0; i < s.size() or j < t.size();){
        if(i == s.size()) no();
        if(j == t.size() or s[i] < t[j]){
            if(i + 1 == s.size()) no();
            ans += s[i + 1] - s[i];
            i += 2;
            continue;
        }
        ans += s[i] - t[j];
        i += 1;
        j += 1;
    }
    cout << ans;
    return 0;
}