#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int k1, k2;
  cin >> k1;
  queue<int> vec1;
  queue<int> vec2;
  int x;
  for (int i = 0; i < k1; i++) {
    cin >> x;
    vec1.push(x);
  }
  cin >> k2;
  for (int i = 0; i < k2; i++) {
    cin >> x;
    vec2.push(x);
  }
  k1 = vec1.size();
  k2 = vec2.size();
  int counter = 0;
  int winner;
  while (k1 != 0 && k2 != 0) {
    int a, b;
    a = vec1.front();
    vec1.pop();
    b = vec2.front();
    vec2.pop();
    if (a > b) {
      vec1.push(b);
      vec1.push(a);
    } else if (b > a) {
      vec2.push(a);
      vec2.push(b);
    }
    k1 = vec1.size();
    k2 = vec2.size();
    counter++;
    if (counter > 9999) {
      cout << "-1";
      return 0;
    }
    if (k1 == 0) winner = 2;
    if (k2 == 0) winner = 1;
  }
  cout << counter << " " << winner;
  return 0;
}
