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

#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
//#define endl        '\n'
#define mod        1000000007
//#define mod        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))
const long double pi=3.14159265359;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{fast;
 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 #endif
 int t=1,n;
 //cin>>t;
 while(t--)
 {cin>>n;
  string a,b;
  cin>>a>>b;
  queue<int> q1,q2;
  rep(i,0,n){
    if(a[i]=='0'){
        q1.push(i);
    }
    else{
        q2.push(i);
    }
  }
  int zero=0,one=0;
  rep(i,0,n){
    if(b[i]=='0') zero++;
    else one++;
  }
  if(zero!=q1.size()||one!=q2.size()){
    cout<<-1<<endl;
    continue;
  }
  int ans=0;
  int i=n-1;
  while(i>=0){
    if(a[i]==b[i]){
        i--;
        continue;
    }
    if(a[i]=='1'){
        int j=i;
        while(a[j]!='0'){
            j--;
        }
        swap(a[i],a[j]);
        i--;
    }
    else{
        int k=i;
        while(b[k]!='0'){
            k--;
        }
        swap(b[i],b[k]);
        i--;
    }
    //cout<<i<<" "<<a<<" "<<b<<endl;
    ans++;
  }
  cout<<ans<<endl;
 }
 return 0;
}

#include <bits/stdc++.h>

#define int long long

using namespace std;

#ifdef LOCAL 
#include "/media/brayand/BrayanD/debugger.h"
#else
#define db(...) false
#define dbl(...) false
#define dbg(...) false
#define dbm(...) false
#define dbs(...) false
#define dbas(...) false
#endif

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin >> N;

    string A, B;
    cin >> A >> B;

    vector<int> v1, v2;

    for(int i = 0 ; i < N ; i++)
    {
    	if(A[i] == '1')
 		{
 			v1.push_back(i);
 		}   		
 		if(B[i] == '1')
 		{
 			v2.push_back(i);
 		}
    }

    if(v1.size() != v2.size())
    {
    	cout << -1 << '\n';
    	return 0;
    }

    int tam = v1.size();

    int res = 0;

    for(int i = 0 ; i < tam ; i++)
    {
    	if(v1[i] == v2[i])continue;
    	if(v1[i] < v2[i])
    	{
    		if(i != tam-1)
    		{
    			if(v1[i+1] <= v2[i])
    			{
    				// db(1);
    				res += v1[i+1]-v1[i]-1;
    			}
    			else
    			{
    				res += v2[i]-v1[i];
    			}
    		}
    		else
    		{
    			res += v2[i]-v1[i];
    		}
    	}
    	if(v1[i] > v2[i])
    	{
    		if(i != 0)
    		{
    			if(v1[i-1] >= v2[i])
    			{
    				res += v1[i]-v1[i-1]-1;
    			}
    			else
    			{
    				res += v1[i]-v2[i];
    			}
    		}
    		else
    		{
    			res += v1[i]-v2[i];
    		}
    	}
    }

    cout << res << '\n';

    return 0;
}