#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
const int inf = 1e9 + 5;
const int mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  int k1, k2;
  cin >> k1;
  deque<int> q1, q2;
  for (int i = 0; i < k1; i++) {
    int x;
    cin >> x;
    q1.push_back(x);
  }
  cin >> k2;
  for (int i = 0; i < k2; i++) {
    int x;
    cin >> x;
    q2.push_back(x);
  }
  int ans = 0, flage = 0;
  while (ans < 10000) {
    int x = q1.front();
    int y = q2.front();
    q1.pop_front();
    q2.pop_front();
    if (x > y) {
      q1.push_back(y);
      q1.push_back(x);
    }
    if (x < y) {
      q2.push_back(x);
      q2.push_back(y);
    }
    ans++;
    if (q1.empty()) {
      flage = 2;
      break;
    }
    if (q2.empty()) {
      flage = 1;
      break;
    }
  }
  if (ans == 10000) {
    printf("-1\n");
  } else {
    printf("%d ", ans);
  }
  if (flage == 1)
    printf("1\n");
  else if (flage == 2)
    printf("2\n");
  return 0;
}
