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

#define debug(x) cerr << #x << '=' << x << endl
#define rep(i, b, e) for (int i = b; i <= e; i++)

char ss1[512345], ss2[512345];
char s1[512345], s2[512345];

int work(char *s1, char *s2, int n) {
    vector<int> a(1), b(1);
    int ans = 0;
    rep (i, 1, n) {
        if (s1[i] == '0') {
            a.push_back(i);
        }
        if (s2[i] == '0') {
            b.push_back(i);
        }
    }
    rep (i, 0, a.size() - 1) {
        if (a.at(i) != b.at(i)) {
            ans++;
        }
    }
    return ans;
}
int main(void) {
    int n, cnt = 0;
    cin >> n;
    scanf("%s%s", ss1 + 1, ss2 + 1);
    rep (i, 1, n) {
        s1[i] = ss1[i];
        s2[i] = ss2[i];
    }
    rep (i, 1, n) {
        if (ss1[i] == '0') {
            cnt++;
        }
        if (ss2[i] == '0') {
            cnt--;
        }
    }
    if (cnt != 0) {
        puts("-1");
        return 0;
    }
    int ans = work(s1, s2, n);
    cout << ans;
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>

int n;
std::string s, t;
std::vector<int> a, b;

int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
    std::cin >> n >> s >> t;
    for (int i = 0; i < s.length(); ++i)
        if (s[i] == '0')
            a.push_back(i);
    for (int i = 0; i < t.length(); ++i)
        if (t[i] == '0')
            b.push_back(i);
    if (a.size() != b.size()) return std::cout << "-1\n", 0;
    int ans = 0;
    for (int i = 0; i < a.size(); ++i)
        if (a[i] != b[i])
            ++ans;
    std::cout << ans << '\n';
    return 0;
}
