/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip> //setprecision
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#include <time.h> //clock
#define endl "\n";
using namespace std;

using PLL = pair<long long,long long>;
using P = pair<int,int>;
const long long INF = 3000000000000000001;
const int inf = 1001001001;
long long MOD = 1000000007;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M, long long mod) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % mod, M / 2,mod);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % mod;
    return res %= mod;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}
long long get_mod(long long res){
    if(res < 0) res += MOD;
    return res % MOD;
}



int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N;cin >> N;
    string S,T;cin >> S >> T;
    set<int> index1;
    for(int i = 0;i<N;i++){
        if(S.at(i) == '1') index1.insert(i);
    }
    long long ans = 0;
    for(int i = 0;i<N;i++){
        if(S.at(i) != T.at(i)){
            auto itr = index1.upper_bound(i);
            if(itr == index1.end()){
                cout << -1 << endl;
                return 0;
            }
            int near1 = *index1.upper_bound(i);
            S.at(near1) = '0';
            S.at(i) = T.at(i);
            ans += near1-i;
            //cout << i << " " << near1 << " " << ans << endl;
            index1.erase(near1);
        }
    }
    cout << ans << endl;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, A, B;
    cin >> N >> A >> B;
    cout << N - A + B << endl;
    return 0;
}