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

int N, ans=0;
string S, T;
vector<int> a, b;

int main(){
  cin >> N >> S >> T;
  bool f=true;
  int x=-1;
  for(int i=0;i<N;i++){
    if(S[i]=='0')a.push_back(i);
    if(T[i]=='0')b.push_back(i);
  }
  if(a.size()!=b.size())puts("-1");
  else{
    for(int i=0;i<a.size();i++){
      if(a[i]!=b[i])ans++;
    }
    cout << ans << endl;
  }

  return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define mod 1000000007

char p[1000005],q[1000005];

ll pre[1000005]={0},ans=0,pre2[1000005]={0},n;

ll solve(ll le,ll ri,ll pos)
{
	if(pos==0) return 0;
	if(le>=ri) return 0;
	if(le==ri-1) 
	{
		ans+=1;return 0;
	}
	ll pos1,pos2;
	
	if(pos==1)
	{
		pos1=le,pos2=le;
	
		while(pos1<=ri)
		{
			if(p[pos1]=='1'&&q[pos1]=='0')
			{
				while(p[pos2]!='0') pos2++;
				if(pos1>=n||pos1<0) while(1);
				
				ans+=1;
				p[pos2]='1';
				
				pos2++;
			}
			pos1++;
		}
	}
	else
	{
		pos1=ri,pos2=ri;
	
		while(pos1>=le)
		{
			if(p[pos1]=='1'&&q[pos1]=='0')
			{
				while(p[pos2]!='0') pos2--;
				if(pos1>=n||pos1<0) while(1);
				
				ans+=1;
				p[pos2]='1';
				
				pos2--;
			}
			pos1--;
		}
	}
	return 0;
}

int main()
{
	ll t,i,j,now1=0,now2=0,nowleft=0,nowway=0,zz1=0,zz2=0;
	cin>>n;
	
	scanf("%s",&p);
	scanf("%s",&q);
	
	for(i=0;i<n;i++)
	{
		if(p[i]=='0') zz1++;
		if(q[i]=='0') zz2++;
	}
	if(zz1!=zz2)
	{
		printf("-1");
		return 0;
	}
	
	if(p[0]=='0') pre[0]=1;
	if(p[0]=='0'&&q[0]=='1') pre2[0]=1; 
	for(i=1;i<n;i++)
	{
		pre[i]=pre[i-1];
		if(p[i]=='0') pre[i]++;
		
		pre2[i]=pre2[i-1];
		if(p[i]=='0'&&q[i]=='1') pre2[i]++;
	}
	
	for(i=0;i<n;i++)
	{
		if(p[i]=='1') now1++;
		if(q[i]=='1') now2++;
		if(now1==now2)
		{
			solve(nowleft,i,nowway);
			nowleft=i+1;
		}
		if(now1>now2) nowway=1;
		else if(now1<now2) nowway=2;
	}
	
	printf("%lld",ans);
	
	return 0;
}