#include<bits/stdc++.h>
using namespace std;
int s0,t0,st; 
int main(){
	int n;cin>>n;
	string s,t;cin>>s>>t;
	for(int i=0;i<n;i++){
		if(s[i]=='0') s0++;
		if(t[i]=='0') t0++;
		if(s[i]=='0'&&t[i]=='0'&&t0==s0)st++;
 	}
 	if(s0!=t0) cout<<-1;
 	else cout<<s0-st;
	return 0;
}
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;

int n,i,j,k,l;
char S[500001];
char T[500001];
int s1[500001],s2[500001];
int ans,sum;

int main()
{
	#ifdef file
	freopen("b.in","r",stdin);
	#endif
	
	scanf("%d",&n);
	scanf("%s",S+1);
	scanf("%s",T+1);
	
	fo(i,1,n)
	{
		s1[i]=s1[i-1]+(S[i]=='0');
		s2[i]=s2[i-1]+(T[i]=='0');
	}
	fo(i,1,n) sum+=S[i]=='0';
	ans=sum;
	fo(i,1,n) sum-=T[i]=='0';
	if (sum) {printf("-1\n");return 0;}
	
	fo(i,1,n)
	if (S[i]==T[i] && S[i]=='0' && s1[i]==s2[i])
	--ans;
	
	printf("%d\n",ans);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}