// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    string s; cin >> s;

    if(s.front() != s.back()) {
        cout << 1 << endl;
        return 0;
    }
    else {
        char c = s.front();
        for(int i=0; i+1<N; i++) {
            if(s[i] != c and s[i+1] != c) {
                cout << 2 << endl;
                return 0;
            }
        }
        cout << -1 << endl;
        return 0;
    }
    return 0;
}

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

template<typename T>
void view_1d(vector<T> V, string sep) {
    for (ll i=0; i<V.size(); i++) {
        cout << V[i];
        if (i == V.size() - 1) {
            cout << endl;
        } else {
            cout << sep;
        }
    }
}

template<typename T>
void view_2d(vector<vector<T>> V, string sep) {
    for (ll i=0; i<V.size(); i++) {
        for (ll j=0; j<V[i].size(); j++) {
            cout << V[i][j];
            if (j == V[i].size() - 1) {
                cout << endl;
            } else {
                cout << sep;
            }
        }
    }
}

//==============================//


int main() {
    int N;
    string S, T;
    cin >> N >> S >> T;

    int tmp = 0;
    for (int i=0; i<N; i++) {
        tmp += (S[i] - '0') - (T[i] - '0');
    }

    int ans = 0;
    if (tmp == 0) {
        vector<int> cnt_S, cnt_T;
        for (int i=0; i<N; i++) {
            if (S[i] == '0') cnt_S.push_back(i);
            if (T[i] == '0') cnt_T.push_back(i);
        }
        for (int j=0; j<cnt_S.size(); j++) {
            if (cnt_S[j] != cnt_T[j]) ans++;
        }
    } else {
        ans = -1;
    }

    cout << ans << endl;
}
