#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
template <class T>
int getbit(T x, int pos) {
  return (x >> (pos - 1)) & 1;
}
template <class T>
void turn_on(T &x, int pos) {
  x = x | ((T)1 << (pos - 1));
}
template <class T>
void turn_off(T &x, int pos) {
  x = x & ~((T)1 << (pos - 1));
}
template <class T>
T sqr(T a) {
  return a * a;
}
int n, a[100002], b[100002];
set<int> s;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    s.insert(a[i]);
  }
  int cnt = 0, cnt2 = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
    cnt += (s.find(b[i]) == s.end());
  }
  for (int i = 1; i <= n; ++i) cnt2 += a[i] != b[i];
  if (cnt >= 2)
    printf("-1");
  else if (cnt == 1) {
    printf("%d", cnt2);
  } else {
    if (cnt2 == 0)
      printf("0");
    else
      printf("%d", cnt2 + 1);
  }
}
