#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 9;
int main() {
  int n, count1 = 0, count2 = 0, sum0 = 0, sum1 = 0;
  cin >> n;
  string a, b;
  cin >> a >> b;
  for (int i = 0; i < n; i++) {
    if (a[i] == '0') count1++;
    if (b[i] == '0') count2++;
  }
  if (count1 != count2) {
    cout << "-1";
  } else {
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) {
        if (a[i] == '0') {
          sum0++;
          if (sum1) {
            sum1--;
          }
        }
        if (a[i] == '1') {
          sum1++;
          if (sum0) {
            sum0--;
          }
        }
      }
    }
    cout << sum0 + sum1;
  }
}
