#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define pow(n,m) powl(n,m)
#define sqrt(n) sqrtl(n)
const ll MAX = 5000000000000000000;
const ll MOD = 1000000007;
//998244353;
void randinit(){srand((unsigned)time(NULL));}
int main(){
    ll N;
    cin >> N;
    string S,T;
    cin >> S >> T;
    if(S == T){
        cout << 0 << endl;
        return 0;
    }
    ll a = 0,b = 0;
    for(ll i = 0;i < N;i++) a += (S[i] == '0');
    for(ll i = 0;i < N;i++) b += (T[i] == '0');
    if(a != b){
        cout << "-1" << endl;
        return 0;
    }
    vector<ll> A(N,-1),B(N,-1);
    ll c = 0;
    for(ll i = 0;i < N;i++){
        if(S[i] == '0'){
            A[i] = c;
            c++;
        }
    }
    c = 0;
    for(ll i = 0;i < N;i++){
        if(T[i] == '0'){
            B[i] = c;
            c++;
        }
    }
    for(ll i = 0;i < N;i++){
        if(S[i] == '0' && A[i] == B[i]) a--;
    }
    cout << a << endl;
}

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second

typedef long long ll;
typedef pair<int,int> ii;

string s;
map<char,int> cnt;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s;
    ll ans = 0;
    for (int i = s.length()-1; i >= 1; i--) {
        if (s[i] == s[i-1]) {
            ans += s.length()-i-1-cnt[s[i]];
            cnt.clear();
            cnt[s[i]] = s.length()-i-1;
        }
        cnt[s[i]]++;
    }
    cout << ans << '\n';
    return 0;
}