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

int32_t main()
{
  int n;cin>>n;
  string s;string t;cin>>s>>t;
  int prev=-1;
  queue<int>q;
  int ans=0;
  for(int i=0;i<n;i++)
  { 
    if (t[i] == '1') 
      q.push(i);
        if (s[i] == '1') 
        {
            if (prev != -1) 
            {
                ans += i - prev;
                prev = -1;
            } 
          	else 
            {
                if (q.empty()) 
                    prev = i;
                 else 
                 {
                    ans += i - q.front();
                    q.pop();
                 }
            }
        }
    }
  if(!q.empty() || prev!=-1)
    cout<<-1<<endl;
  else
    cout<<ans<<endl;
}
#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define ll long long
#define ull unsigned long long
#define y1 orzkcz
using namespace std;
const int N=500005;
int n,q1[N],q2[N];
char s[N],t[N];
ll res;
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	For(i,1,n) if (s[i]=='1') q1[++*q1]=i;
	For(i,1,n) if (t[i]=='1') q2[++*q2]=i;
	int p=1;
	For(i,1,*q2){
		for (;p<=*q1&&q2[i]>q1[p];p+=2)
			res+=q1[p+1]-q1[p];
		if (p>*q1) return puts("-1"),0;
		res+=q1[p]-q2[i]; ++p;
	}
	for (;p<=*q1;p+=2)
		res+=q1[p+1]-q1[p];
	if (p!=(*q1)+1)
		puts("-1");
	else
		printf("%lld\n",res);
}