#include <bits/stdc++.h>
using namespace std;
int a[10000010], b[10000010], s, n, la, lb, ia, ib;
int main() {
  cin >> n;
  cin >> la;
  for (int i = 1; i <= la; i++) {
    cin >> a[i];
  }
  cin >> lb;
  for (int i = 1; i <= lb; i++) {
    cin >> b[i];
  }
  ia = ib = 1;
  while (ia <= la && ib <= lb && la < (1 << 20)) {
    s++;
    if (a[ia] > b[ib]) {
      a[++la] = b[ib];
      a[++la] = a[ia];
    } else {
      b[++lb] = a[ia];
      b[++lb] = b[ib];
    }
    ia++;
    ib++;
  }
  if (la >= (1 << 20)) {
    cout << -1 << endl;
  } else {
    cout << s << ' ';
    if (ia > la) {
      cout << 2 << endl;
    } else {
      cout << 1 << endl;
    }
  }
  return 0;
}
