#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long n, i, j, cnt, ans, m;
string second, t;
deque<pair<long long, long long>> v;
signed main() {
  iostream::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> second >> t;
  for (char h : second) cnt += h - '0';
  for (char h : t) cnt -= h - '0';
  if (cnt != 0) {
    cout << "-1";
    exit(0);
  }
  for (i = 0; i < n; i++) {
    if (second[i] == t[i]) continue;
    j = i + 1;
    cnt = 1;
    while (j < n) {
      if (second[j] == t[j]) {
        j++;
        continue;
      }
      if (second[i] != second[j]) break;
      cnt++;
      j++;
    }
    v.push_back({second[i] - '0', cnt});
    i = j - 1;
  }
  while (v.size() > 0) {
    if (v[0].first == 1) {
      if (v.back().first == 1) {
        v[0].second += v.back().second;
        v.pop_back();
      }
    } else {
      if (v.back().first == 0)
        v.back().second += v[0].second;
      else
        v.push_back(v[0]);
      v.pop_front();
    }
    m = 1e9;
    for (auto x : v) m = min(m, x.second);
    ans += m;
    for (i = 0; i < v.size(); i++) v[i].second -= m;
    deque<pair<long long, long long>> v1 = v;
    v.clear();
    for (i = 0; i < v1.size(); i++) {
      if (v1[i].second == 0) continue;
      j = i + 1;
      cnt = v1[i].second;
      while (j < v1.size()) {
        if (v1[j].second == 0) {
          j++;
          continue;
        }
        if (v1[i].first != v1[j].first) break;
        cnt += v1[j].second;
        j++;
      }
      v.push_back({v1[i].first, cnt});
      i = j - 1;
    }
  }
  cout << ans;
  return 0;
}
