#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
map<int, int> num;
map<int, int>::iterator ddq;
int n, i, j, k, l, x, y, ans, a[N], b[N], c[N], d[N], cnt;
bool brg[N];
int Abs(int a) { return a > 0 ? a : -a; }
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    num[a[i]]++;
  }
  for (i = 1; i <= n; ++i) {
    scanf("%d", b + i);
    num[b[i]]--;
  }
  x = y = -1;
  for (ddq = num.begin(); ddq != num.end(); ddq++)
    if (Abs(ddq->second) >= 2) {
      printf("-1");
      return 0;
    } else if (ddq->second == 1) {
      if (x == -1)
        x = ddq->first;
      else {
        printf("-1");
        return 0;
      }
    } else if (ddq->second == -1) {
      if (y == -1)
        y = ddq->first;
      else {
        printf("-1");
        return 0;
      }
    }
  if (x != -1) {
    for (i = 1; i <= n; ++i)
      if (a[i] == x && b[i] != y) {
        a[i] = y;
        break;
      }
    if (i > n) {
      for (i = 1; i <= n; ++i)
        if (a[i] == x) {
          a[i] = y;
          ++ans;
          break;
        }
    }
    for (i = 1; i <= n; ++i)
      if (a[i] != b[i]) ++ans;
  } else {
    for (i = 1; i <= n; ++i)
      if (a[i] != b[i]) ++ans;
    if (ans) ++ans;
  }
  printf("%d", ans);
  return 0;
}
