#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int n;
int a[MAXN], b[MAXN];
set<int> vis1, vis2;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[i]) continue;
    if (vis1.count(a[i]) || vis2.count(b[i])) return puts("-1"), 0;
    vis1.insert(a[i]);
    vis2.insert(b[i]);
  }
  puts("0");
}
