#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> x, pair<int, int> y) { return x.second < y.second; }
int main() {
  queue<int> q1, q2;
  int cnt = 0, n, k1, k2, x;
  scanf("%d", &n), scanf("%d", &k1);
  for (int i = 0; i < k1; i++) {
    scanf("%d", &x);
    q1.push(x);
  }
  scanf("%d", &k2);
  for (int i = 0; i < k2; i++) {
    scanf("%d", &x);
    q2.push(x);
  }
  while (!q1.empty() && !q2.empty()) {
    if (q1.front() > q2.front()) {
      q1.push(q2.front());
      q1.push(q1.front());
      q1.pop(), q2.pop();
    } else {
      q2.push(q1.front());
      q2.push(q2.front());
      q1.pop(), q2.pop();
    }
    cnt++;
    if (cnt == (long long)(1e4)) {
      printf("%d ", -1);
      return 0;
    }
  }
  printf("%d ", cnt);
  if (q1.empty())
    printf("%d ", 2);
  else
    printf("%d ", 1);
  return 0;
}
