#include <iostream>
#include <string>
#include <vector>

int main(){
  int n;
  std::string s, t;
  std::cin >> n >> s >> t;

  int ans = 0;
  int sums = 0;
  int sumt = 0;
  for(int i = 0; i < n; i++){
    sums += s[i] - '0';
    sumt += t[i] - '0';
    if(s[i] < t[i] && sums < sumt) ans++;
    if(s[i] > t[i] && sums > sumt) ans++;
    else if(s[i] == '0' && t[i] == '0' && sums != sumt) ans++;
  }
  if(sums == sumt) printf("%d\n", ans);
  else puts("-1");


  return 0;
}

//
//  main.cpp
//  test
//
//  Created by wyzwyz on 2021/5/13.
//

#include<cstdio>
#include<cctype>

#define maxn 505505

template<class T>

inline T read(){
    T r=0,f=0;
    char c;
    while(!isdigit(c=getchar()))f|=(c=='-');
    while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar();
    return f?-r:r;
}

template<class T>

inline T min(T a,T b){
    return a<b?a:b;
}

int n,s_a[2],a[2][maxn];

char s[maxn],t[maxn];

int main(){
    n=read<int>();
    scanf("%s\n%s",s+1,t+1);
    for(int i=1;i<=n;i++){
        if(s[i]=='0')a[0][++s_a[0]]=i;
        if(t[i]=='0')a[1][++s_a[1]]=i;
    }
    if(s_a[0]^s_a[1])return puts("-1"),0;
    int ans=0;
    for(int i=1;i<=s_a[0];i++)
    ans+=(a[0][i]-a[1][i])!=0;
    printf("%d\n",ans);
    return 0;
}