#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>
#define mp make_pair

using namespace std;

const int nax = 5e5 + 5;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    int n; cin>>n;
    string s,t; cin>>s>>t;
    int bal = 0;
    for(int i=n-1;i>=0;i--)
    {
        if(s[i] == '1') bal++;
        if(t[i] == '1') bal--;

        if(bal < 0)
        {
            cout<<-1;
            return 0;
        }
    }

    if(bal % 2 == 1)
    {
        cout<<-1;
        return 0;
    }

    vector<int> pos1;
    vector<int> pos2;
    for(int i=0;i<n;i++)
    {
        if(s[i] == '1') pos1.pb(i);
        if(t[i] == '1') pos2.pb(i);
    }

    stack<int> wyjebansko;
    ll ans = 0;
    int done = 0;
    for(int i=0;i<pos1.size();i++)
    {
        int cur = pos1[i];
        if(wyjebansko.size() == 1)
        {
            int pop = wyjebansko.top();
            wyjebansko.pop();
            ans += (cur - pop);
        }
        else
        {
            if(done < pos2.size() && cur >= pos2[done])
            {
                ans += cur - pos2[done];
                done++;
            }
            else wyjebansko.push(cur);
        }
    }
    cout<<ans;




    return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 500005;

int n;
char s[N], t[N];

int solve() {
  scanf("%d", &n);
  scanf("%s", s);
  scanf("%s", t);

  vector<int> v1, v2;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '1') v1.push_back(i);
    if (t[i] == '1') v2.push_back(i);
  }

  long long ans = 0;
  int cur = 0;
  for (int i = 0; i < v1.size(); ++i) {
    if (cur >= v2.size() || v2[cur] > v1[i]) {
      if (i + 1 >= v1.size()) return 0 * printf("-1\n");
      ans += v1[i + 1] - v1[i];
      ++i;
    } else {
      ans += v1[i] - v2[cur];
      ++cur;
    }
  }

  if (cur < v2.size()) return 0 * printf("-1\n");

  printf("%lld\n", ans);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    solve();
  }
  return 0;
}
