#include <bits/stdc++.h>
#define endl "\n"
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define ll long long
#define llu unsigned long long
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define ABS(X) ((X) < 0 ? -(X) : (X))
#define LCM(X, Y) (((X) / (GCD((X), (Y)))) * (Y))
#define MEM(A, B) memset((A), (B), sizeof(A))
#define MEM_VEC(V, FILL) fill(V.begin(), V.end(), FILL)
#define FOR_EACH(IT, V) for (auto IT = V.begin(); IT != V.end(); IT++)
#define DEBUG_ARRAY_PRINT(A, I) cout << "at pos " << I << "  value is: " << A[I]
#define TURBO                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
using namespace std;
inline ll GCD(ll A, ll B)
{
    if (B == 0)
        return A;
    return GCD((B), (A % B));
}
inline ll POW(ll BASE, ll EXP)
{
    ll RES = 1;
    for (ll I = 0; I < EXP; I++)
        RES *= BASE;
    return RES;
}
inline ll BIGMOD(ll a, ll p, ll m)
{
    ll res = 1 % m;
    ll x = a % m;
    while (p > 0)
    {
        if ((p & 1) > 0)
            res = (res * x) % m;
        x = (x * x) % m;
        p >>= 1;
    }
    return res;
}
inline void FILE_HANDLE()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    TURBO;
    //FILE_HANDLE() ;
    int n, a, b;
    cin >> n >> a >> b;
    cout << n - a + b << endl;
}
// Coder: @SumitRaut
#include <bits/stdc++.h>
#define speedup ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr),cout.precision(16)
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
#define sbc __builtin_popcount
#define pb push_back
#define em emplace
#define emb emplace_back
#define ff first
#define ss second
#define ll long long
const ll mod = 1e9+7;

template<typename T> void smax(T& a, T b) { if(a<b) a=b; }
template<typename T> void smin(T& a, T b) { if(a>b) a=b; }
template<typename T> T pw(T a,T b) { T p=1,one=1; while(b) { if(b&one) p=p*a; a=a*a; b >>=1; } return p; }
template<typename T> T pwm(T a,T b,T md=mod) { T p=1,one=1; while(b) { if(b&one) p=p*a%md; a=a*a%md; b >>=1; } return p; }

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
	for(auto& it:v)
		is>>it;
	return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto &it : v)
		os << it << ' ';
	return os;
}

#ifndef ONLINE_JUDGE
class Timer { chrono::high_resolution_clock::time_point start_t, end_t; public: Timer() { start_t=chrono::high_resolution_clock::now(); } ~Timer() { end_t = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(end_t-start_t); cerr<<"\nRunTime: "<<duration.count()<<"ms"<<'\n'; } };
void debug() { cerr << '\n'; }
template <typename T, typename... Args>
void debug(T print, Args... args) { cerr << ' ' << print; debug(args...); }
#define deb(...) cerr << "[" << #__VA_ARGS__ << "]" << " --> ", debug(__VA_ARGS__)
#else
#define deb(...) void(0)
#endif

void solve() {
	int n;
	string s,t;
	cin>>n>>s>>t;
	int j=0;
	ll res=0;
	for(int i=0;i<n;++i) {
		if(s[i]!=t[i]) {
			smax(j,i+1);
			while(j<n&&s[j]!='1') ++j;
			if(j==n) {
				cout<<"-1\n";
				return;
			}
			res+=j-i;
			s[j]='0';
		}
	}
	cout<<res<<'\n';
}

int main() {
	#ifndef ONLINE_JUDGE
	Timer timer;
	#endif
	speedup;
	//int t; cin>>t; while(t--)
	solve();
}
