/*         ====Bismillahir Rahmanir Rahim=====

                    ===ImRan Hossen===

    ==Bangladesh University Of Business And Technology==

*/

#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>
#include <ctime>
using namespace std;


template< class T > T _abs(T n) { return (n < 0 ? -n : n); }
template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); }
template< class T > T _min(T a, T b) { return (a < b ? a : b); }
template< class T > T sq(T x) { return x * x; }


#define pocount     __builtin_popcountll
#define pf          printf
#define PB          push_back
#define MP          make_pair
#define fi          first
#define se          second
#define MOD         1000000007
#define si(a)       scanf("%d",&a)
#define sii(a,b)    scanf("%d%d",&a,&b)
#define siii(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define sl(a)       scanf("%lld",&a)
#define sll(a,b)    scanf("%lld%lld", &a,&b)
#define slll(a,b,c) scanf("%lld%lld%lld", &a, &b, &c)
#define ss(s)	    scanf("%s",s)
#define RESET(a, b) memset(a, b, sizeof(a))

#define all(v)      v.begin(),v.end()
#define rall(v)     v.rbegin(),v.rend()
#define SORT(v)     sort(all(v))
#define REVERSE(v)  reverse(all(v))
#define PERMUTE     next_permutation
#define TC(t)       while (t--)

#define FOR(a, b, c)    for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c)   for (int(a) = (b); (a) <= (c); ++(a))
#define REP(i, n)       FOR(i, 0, n)
#define REPN(i, n)      FORN(i, 1, n)
#define SET(p)          memset(p, -1, sizeof(p))
#define CLR(p)          memset(p, 0, sizeof(p))
#define MEM(p, v)       memset(p, v, sizeof(p))
#define SZ(c)           (int)c.size()

#ifdef TESTING
#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define DEBUG
#define VALUE(x)
#define debug(...)
#endif


#define FasterIO    ios_base::sync_with_stdio(false); cin.tie(NULL);

const double pi = acos(-1.0);

typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;

int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };

class TimeTracker {
    clock_t start, end;
public:
    TimeTracker() {
        start = clock();
    }
    ~TimeTracker() {
        end = clock();
        fprintf(stderr, "%.3lf s\n", (double)(end - start) / CLOCKS_PER_SEC);
    }
};



int main()
{
    //FaterIO

    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	///TimeTracker a;

	int n, A[1010], mark[1010], i, flag;

	scanf("%d", &n);

        flag = 0;

        CLR(mark);

        for(i = 0; i < n; i++){
            scanf("%d",&A[i]);
            if(mark[A[i]]>0)flag = 1;
            mark[A[i]]++;
        }

        if(flag)
        {
            printf("No\n");
        }
        else printf("Yes\n");






    return 0;
}










//Don't Get panic
//Take it easy
//what about n=1 or n=2 and corner case and also critical case
//If failed in system test read the problem again
//Bug is part of code


#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;
}
