#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define ll long long
using namespace std;

const int MAX = 5e5+50;
char s[MAX], t[MAX];
int n;
vector<int> a, b;

int main() {
	scanf("%d%s%s", &n, s + 1, t + 1);
	for (int i = 1; i <= n; i++) {
		if (s[i] == '0') a.emplace_back(i);
		if (t[i] == '0') b.emplace_back(i);
	}
	if (SZ(a) != SZ(b)) {
		puts("-1");
		return 0;
	}
	int sum = 0;
	for (int i = 0; i < SZ(a); i++) sum += a[i] != b[i];
	printf("%d\n", sum);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int ll

int get(string s,string t){
    int n=s.size();
    set<int> zero;
    set<int> one;
    for(int i=0;i<n;i++){
        if(s[i]=='0'){
            zero.insert(i);
        }else{
            one.insert(i);
        }
    }
    int ans=0;
    set<int> st;
    for(int i=0;i<n;i++){
        if(s[i]!=t[i])st.insert(i);
    }
    for(int i=0;i<n;i++){
        deb(i);
        if(s[i]!=t[i]){
            if(t[i]=='0'){
                ++ans;
                assert(zero.size()>0);
                int pos=*zero.begin();
                zero.erase(zero.begin());
                s[pos]='1';
                one.insert(pos);
            }else{
                deb("else");
                int pos=*one.begin();
                one.erase(one.begin());
                int x=*zero.begin();
                int y=n-1;
                auto zit=zero.lower_bound(pos);
                if(zit!=zero.end()){
                    y=*zit;--y;
                }
                auto eit=st.lower_bound(pos);
                int rpos=pos;
                if(eit!=st.end()){
                    rpos=*eit;
                }
                int z=n;
                auto sit=zero.lower_bound(x+1);
                if(sit!=zero.end()){
                    z=*sit;
                    // zero.erase(zero.begin());                    
                }
                if(z<pos){
                    ans+=pos-i;
                    s[rpos]='0';
                    zero.insert(rpos);
                }else{
                    ++ans;
                    s[rpos]='0';
                    zero.insert(rpos);
                }
                
            }
            st.erase(i);
        }
    }
    return ans;
}

int get_ans(string &s,string &t){
    int ans=min(get(s,t),get(t,s));
    reverse(all(s));reverse(all(t));
    return min(ans,min(get(s,t),get(t,s)));
}

int optiaml(string s,string t){
    int n=s.size();
    if(count(all(s),'0')!=count(all(t),'0'))return -1;
    vector<int> v;
    for(int i=0;i<n;i++){
        if(t[i]=='0')v.emplace_back(i);
    }
    int ans=0,j=0;
    for(int i=0;i<n;i++){
        if(s[i]=='0'){
            ans+=(i!=v[j++]);
        }
    }
    return ans;
}

void solve()
{
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    cout<<optiaml(s,t)<<"\n";
}

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("../text_files/input.txt", "r", stdin);
    freopen("../text_files/output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}