#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 s1[512345], s2[512345];
vector<int> a(512345);
vector<int> b(512345);
signed main(void) {
    int n, cnt = 0;
    cin >> n;
    scanf("%s%s", s1 + 1, s2 + 1);
    rep (i, 1, n) {
        if (s1[i] == '0') {
            cnt++;
        }
        if (s2[i] == '0') {
            cnt--;
        }
    }
    if (cnt != 0) {
        puts("-1");
        return 0;
    }
    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, min(a.size(), b.size()) - 1) {
        if (a[i] != b[i]) {
            ans++;
        }
    }
    cout << ans;
    return 0;
}

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


/*
ll fac[100000+1];
ll power(ll x,ll y)
{
    ll res = 1; // Initialize result

    x = x % k; // Update x if it is more than or
    // equal to p

    while (y > 0)
    {

        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % k;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) %k;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n)
{
    return power(n, k - 2);
}

// Returns nCr % p using Fermat's little
// theorem.
ll nCr(ll n,ll r)
{
    // If n<r, then nCr should return 0
    if (n < r)
        return 0;
    // Base case
    if (r == 0)
        return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r


    return (fac[n] * modInverse(fac[r]) % k
            * modInverse(fac[n - r]) % k)
           % k;
}
*/
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;

        return gcd(b%a,a);
}

ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            if (n / i == i)
                cnt++;

            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}
/*ll binexp(ll a,ll b)
{
    if(a==0||a==1) return a;
    if(b==0)  return 1;
    ll ret= binexp(a,b/2);
    if(b%2) return (((ret*ret)%M)*a)%M;
    else return (ret*ret)%M;
}
*/
ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll maxPrimeFactor(ll n)
{
    ll maxPrime = -1;
    while (n % 2 == 0) {
        maxPrime = 2;
        n >>= 1;
    }
    for (ll i = 3; i <= sqrt(n); i += 2) {
        while (n % i == 0) {
            maxPrime = i;
            n = n / i;
        }
    }
    if (n > 2)
        maxPrime = n;
    return maxPrime;
}
ll isPrime(ll n)
{
    if(n==1) return 0;
       if (n <= 3)  return (1);
    if (n%2 == 0 || n%3 == 0) return (0);
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return (0);

    return (1);
}

ll no_of_digits(ll n)
{
   ll k=0;
   while(n)
   {
       k++;
       n/=10;
   }
  return k;
}
ll sum_of_digits(ll n)
{
   ll k=0;
   while(n)
   {
       k+=n%10;
       n/=10;
   }
  return k;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   /*ll fac[11];
    fac[0] = 1;
    for (int i = 1; i <=10; i++)
        fac[i] = (fac[i - 1] * i);*/

   ll t=1;
 //  cin>>t;
    while(t--){
         int n;
         cin>>n;
         string s,t;
         cin>>s>>t;
         vector<int> v1,v2,v3,v4;
         for(int i=0;i<n;i++)
         {
             if(s[i]=='0')
                v1.push_back(i);
                else
                    v3.push_back(i);
             if(t[i]=='0')
                v2.push_back(i);
                else
                    v4.push_back(i);
         }
       //  cout<<v1.size()<<" "<<v2.size();

       if(s==t)
        cout<<0;
        else if(v1.size()!=v2.size())
            cout<<-1;
         else{
        int count1=0,count2=0;
         int i=0;
         while(i<v1.size())
         {
             if(v1[i]==v2[i])
             count1++;
             i++;
         }
        /* int j=v1.size()-1;
          while(j>=0 && v1[j]==v2[j])
         {
             count2++;
             j--;
         }*/
        // cout<<count1<<" "<<count2;
         ll ans1=v1.size()-count1-count2;
        count1=0,count2=0;
          i=0;
         while(i<v3.size() && v3[i]==v4[i])
         {
             count1++;
             i++;
         }
        int j=v3.size()-1;
          while(j>=0 && v3[j]==v4[j])
         {
             count2++;
             j--;
         }
        // ll ans2=v3.size()-count1-count2;
         cout<<ans1;
         }
       cout<<"\n";
        }
    return 0;
}
