#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 500005
#define INF 0x3f3f3f3f
int n,cs=0,ct=0,ps[N],pt[N];
char s[N],t[N];
ll ans=0;
int main(){
	//freopen("b.in","r",stdin);
	//freopen("b.out","w",stdout);
	scanf("%d%s%s",&n,s,t);
	for(int i=0;i<n;++i){
		if(s[i]=='1') ps[++cs]=i;
		if(t[i]=='1') pt[++ct]=i;
	}
	pt[ct+1]=INF;
	if(cs<ct||((cs-ct)&1)){
		puts("-1");
		return 0;
	}
	for(int i=1,j=1;;++i,++j){
		while(j<=cs&&pt[i]>ps[j]){
			ans+=ps[j+1]-ps[j];
			j+=2;
		}
		if(j>cs){
			if(i>ct)printf("%lld\n",ans);
			else puts("-1");
			return 0;
		}
		ans+=ps[j]-pt[i];
	}
	
	return 0;
}
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int k, ans;
string s;

bool C(int x) {
  bool b[10] = {};
  b[x % 10] = b[x / 10 % 10] = b[x / 100 % 10] = b[x / 1000] = true;
  for (int i = 0; i <= 9; i++) {
    if (s[i] == 'o' && !b[i] || s[i] == 'x' && b[i]) {
      return false;
    }
  }
  return true;
}

int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  for (int i = 0; i <= 9; i++) {
    k += s[i] == 'o';
  }
  for (int i = 0; i <= 9999; i++) {
    ans += C(i);
  }
  cout << ans;
  return 0;
}
