#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int n;
const int maxn = 5e5 + 10;
char s[maxn], t[maxn];
queue<int> q;
int main() {
	while(~scanf("%d%*c", &n)) {
		while(!q.empty()) q.pop();
		int cnt1 = 0, cnt2 = 0; ll ans = 0;
		for(int i = 1; i <= n; i++) scanf("%1d", &s[i]), cnt1 += s[i];
		for(int i = 1; i <= n; i++) scanf("%1d", &t[i]), cnt2 += t[i];
		for(int i = 1; i <= n; i++) if(s[i] == 1) q.push(i);
		for(int i = 1; i <= n; i++) {
			if(t[i] == 0) {
				if(!q.empty() && q.front() <= i) {
					cnt1 -= 2;
					if(cnt1 < cnt2) {
						ans = -1;
						break;
					}
					int x = q.front(); q.pop();
					int y = q.front(); q.pop();
					ans += y-x;
				}
			}
			else {
				int x = q.front(); q.pop();
				ans += x-i;
			}
		}
		printf("%lld\n", ans);
	}
	//system("pause");
    return 0;
}
#include<iostream>
#include<assert.h>
#define int long long
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define infi INT_MAX
#define rinfi INT_MIN
#define inf LLONG_MAX
#define rinf LLONG_MIN
#define ff first
#define ss second
#ifndef ONLINE_JUDGE
#define line cout<<"here - "<<__LINE__<<"\n";
#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
#define db(a,b) cout<<#a<<" --> "<<(a)<<"\n";cin>>b;
#else
#define line
#define dbg(a)
#define db(a,b)
#endif
char _;
using namespace std;
int i,j,a;
 string s,t;
void go()
{
    while(i<a && s[i]=='0')
        i++;
}
main()
{
//    fast
    int tc=1,k;
//    cin>>tc;
//    getchar();
    while(tc--)
    {
     cin>>a;
     cin>>s>>t;
     int ans=0;
     i=0;j=0;
     a=s.size();
     while(j<a)
     {
         while(i<a && s[i]=='0')
            i++;
         while(j<a && t[j]=='0')
            j++;
            int cnt=i;
            int ok=0,m=0;
            while(i<j && j<a && i<a)
            {
                int cnt=i;
                i++;
               go();
               ans+=i-cnt;
               i++;
               go();
            }
            dbg(ans)
         if(j<a && t[j]=='1')
         {
             if(i<j || i>=a)
             {
                 cout<<-1<<endl;
                 return 0;
             }

         }
         else if(j==a){
            break;
         }
         dbg(i) dbg(j)
         ans+=i-j;
         i++;
         j++;

     }
     dbg(i) dbg(j)
     assert(i<=a);
     assert(j<=a);
     for(;i<a;i++)
     {
         if(s[i]=='1')
         {
              int cnt=i;
              i++;
              go();
              if(i>=a)
              {
                  cout<<-1<<endl;
                  return 0;
              }
              ans+=i-cnt;
         }
     }
     cout<<ans<<endl;
     i=0,j=0;
    }
}


