#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> intA, intB, SintA, SintB;
  int i;
  for (i = 0; i < N; i++) {
    int a;
    cin >> a;
    intA.push_back(a);
    SintA.push_back(a);
  }
  int ii;
  for (ii = 0; ii < N; ii++) {
    int b;
    cin >> b;
    intB.push_back(b);
    SintB.push_back(b);
  }
  sort(SintA.begin(), SintA.end());
  ;
  sort(SintB.begin(), SintB.end());
  ;
  int iii, minus;
  for (iii = 0; iii < N; iii++) {
    if (intA[iii] == intB[iii]) {
      minus++;
    }
    if (minus == N) {
      cout << 0 << endl;
      exit(0);
    }
  }
  int I, ans;
  for (I = 0; I < N; I++) {
    if (SintA[I] == SintB[I]) {
      ans++;
    }
  }
  if (ans == N) {
    cout << N + 1 - minus << endl;
  } else if (ans == N - 1) {
    cout << N - minus << endl;
  } else {
    cout << -1 << endl;
  }
}
