#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 5;
const int MOD = 1000 * 1000 * 1000 + 7;
const long double EPS = 1e-9;
const int MAXN = 1000 * 1000;
int a[MAXN], b[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int k1, k2;
  cin >> k1;
  for (int i = 0; i < k1; i++) {
    cin >> a[i];
  }
  cin >> k2;
  for (int j = 0; j < k2; j++) {
    cin >> b[j];
  }
  int l1 = 0, r1 = k1, l2 = 0, r2 = k2;
  int cnt = 0;
  while (1) {
    if (l1 == r1) {
      cout << cnt << " " << 2 << endl;
      return 0;
    }
    if (l2 == r2) {
      cout << cnt << " " << 1 << endl;
      return 0;
    }
    int nea = a[l1++], neb = b[l2++];
    if (nea > neb) {
      a[r1++] = neb;
      a[r1++] = nea;
    } else {
      b[r2++] = nea;
      b[r2++] = neb;
    }
    cnt++;
    if (cnt > MAXN / 10) break;
  }
  cout << -1;
  return 0;
}
