#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
  x=0;char ch=getchar();bool f=0;
  for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') f=1;
  for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
  if(f) x=-x;
  return;
}
typedef long long ll;
typedef double db;
const int mod=998244353,G=3,phi=998244352;
int n;
const int N=5e5+10;
char s[N],t[N];
int main(){
  init(n);
  scanf("%s",s+1);
  scanf("%s",t+1);
  int h1=1,h2=1;
  int cnt=0;
  bool fl=0;
  while(h1<=n||h2<=n) {
    while(h1<=n&&s[h1]!='0') ++h1;
    while(h2<=n&&t[h2]!='0') ++h2;
    if(h1<=n&&h2<=n) {
      if(h1!=h2) ++cnt;
      ++h1,++h2;
    }else if(h1>n&&h2>n);
    else {fl=1;break;}
  }
  if(fl) puts("-1");
  else printf("%d\n",cnt);
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define closeSync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int MAXN = 300005;
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 0x3f3f3f3f;

vector<int> v[2];

inline void solve()
{
    int n;  cin >> n;
    string S,T; cin >> S >> T;
    S = " " + S,T = " " + T;

    for (int i=1;i<=n;i++)
        if (S[i] == '0')
            v[0].push_back(i);
    for (int i=1;i<=n;i++)
        if (T[i] == '0')
            v[1].push_back(i);
    
    if (v[0].size() != v[1].size())
        cout << "-1\n";
    else 
    {
        int ed = v[0].size() - 1;
        int cnt = 0;
        for (int i=0;i<=ed;i++)
            if (v[0][i] != v[1][i])
                cnt++;
        cout << cnt << "\n";
    } 
    return ;
}

int main()
{closeSync;
    solve();
    return 0;
}