#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10 + 1e6;
const long long MOD = 998244353;
int n, k;
long long dp[MAXN], b[MAXN][2];
pair<long long, long long> a[MAXN];
string s, t;
void Inout() {
  freopen(
      "ABC"
      ".inp",
      "r", stdin);
  freopen(
      "ABC"
      ".out",
      "w", stdout);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  cin >> s;
  cin >> t;
  int x = 0, mi = n, ma = -1;
  for (int i = 0; i < n; ++i) {
    x += (s[i] - t[i]);
    mi = min(mi, x);
    ma = max(ma, x);
  }
  (x == 0) ? cout << ma - mi : cout << -1;
  return 0;
}
