#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  int sc = 0, tc = 0;
  vector<int> P(N + 1, N - 1);
  for (int i = N - 1; i > -1; i--) {
    if (S[i] == '1') {
      P[i] = i;
      sc++;
    } else if (S[i] == '0') {
      P[i] = P[i + 1];
    }
    if (T[i] == '1') tc++;
    if (sc < tc) {
      cout << -1 << '\n';
      return 0;
    }
  }
  if (sc < tc || (sc > tc && (sc - tc) % 2 != 0)) {
    cout << -1 << '\n';
    return 0;
  }
  int pos = P.front();
  int64_t res = 0;
  for (int i = 0; i < N; i++) {
    if (T[i] == '1') {
      int j = pos;
      S[j] = '0';
      res += j - i;
      pos = P[j + 1];
    } else if (S[i] == '1') {
      int j = P[i + 1];
      S[i] = '0';
      S[j] = '0';
      res += j - i;
      pos = P[P[j + 1]];
    }
  }
  cout << res << '\n';
  return 0;
}

//  “Alhamdulillah for Everything”
#include<bits/stdc++.h>
using namespace std;

#define      pai              acos(-1)
#define      ff               first
#define      ss               second
#define      ll               long long
#define      pb               push_back
#define      mp               make_pair
#define      pll              pair<ll,ll>
#define      sz(a)            (ll)a.size()
#define      endl             "\n"
#define      gcd(a, b)        __gcd(a, b)
#define      lcm(a, b)        ((a*b)/gcd(a,b))
#define      all(vec)         vec.begin(),vec.end()
#define      ms(a, b)         memset(a,b,sizeof(a))
#define      rep(i,b,n)       for(ll i = b;i <= n; i++)
#define      rev(i,b,n)       for(ll i = b;i >= n; i--)
#define      watch(x)         cout<<(#x)<<" = "<<(x)<<'\n'
#define      TEST_CASE(t)     for(ll zz=1;zz<=t;zz++)
#define      PRINT_CASE       cout<<"Case "<<zz<<": ";
#define      fii              freopen("input.txt","r",stdin);
#define      foo              freopen("output.txt","w",stdout);
#define      boom             ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const ll mod = 1e9+7;
const ll mxn = 1e5+7;
const ll inf = 1e18;

ll sumd(ll a,ll b){return (((a%mod)+(b%mod))%mod);}
ll muld(ll a,ll b){return (((a%mod)*(b%mod))%mod);}
ll subd(ll a,ll b){return (((a%mod)-(b%mod)+mod)%mod);}


int  main()
{
    boom;
    double a,b,c,d,n,m,x,y,z;
    cin>>a>>b>>c;
    d = b/a;
    n = ceil(d*c);
    for(ll i=n;i>=0;i--)
    {
        m = i/c;
        if(m<d)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}

