#include<bits/stdc++.h>
using namespace std;
#define MAXN 500005
char s[MAXN],t[MAXN];
int n,cnt1,cnt2;
int main()
{
    scanf("%d",&n);
    scanf("%s %s",s,t);
    for(int i=0;i<n;i++)if(s[i]=='0')cnt1++;
    for(int i=0;i<n;i++)if(t[i]=='0')cnt2++;
    if(cnt1!=cnt2)printf("-1\n");
    else
    {
        int i=0,j=0;
        while(1)
        {
            while(i<n&&s[i]=='1')i++;
            while(j<n&&t[j]=='1')j++;
            if(i>=n)break;
            i++,j++;
            if(i==j)cnt1--;
        }
        printf("%d\n",cnt1);
    }
    return 0;
}
#include <algorithm>
#include <chrono>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <assert.h>

//#pragma GCC optimize("O3")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MOD = 998244353;
const ld EPS = 1e-11;
const ld MEPS = EPS * 1e2;
const ll INFL = 2e18;
const int INF = 1e9 + 7;
const ld PI = acos(-1);
const ld E = exp(1);

mt19937 rnd((unsigned)chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    string s, t;
    cin >> s >> t;

    vector<int> is, it;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '0') {
            is.push_back(i);
        }
        if (t[i] == '0') {
            it.push_back(i);
        }
    }

    if (is.size() != it.size()) {
        cout << "-1\n";
        return 0;
    }

    int ans = 0;
    for (int i = 0; i < is.size(); ++i) {
        if (is[i] != it[i]) {
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}