#include <bits/stdc++.h>
using namespace std;
map<pair<long long int, long long int>, bool> mymap;
int main() {
  int n;
  cin >> n;
  long long int pow100[11];
  pow100[0] = 1;
  for (int i = 1; i <= 10; i++) {
    pow100[i] = 100 * pow100[i - 1];
  }
  long long int p1 = 0, p2 = 0;
  int k1, k2, temp;
  cin >> k1;
  for (int i = 0; i < k1; i++) {
    cin >> temp;
    p1 = p1 * 100 + temp;
  }
  cin >> k2;
  for (int i = 0; i < k2; i++) {
    cin >> temp;
    p2 = p2 * 100 + temp;
  }
  long long int fights = 0;
  while (1) {
    if (mymap[make_pair(p1, p2)]) {
      cout << -1 << endl;
      return 0;
    }
    mymap[make_pair(p1, p2)] = true;
    if (p1 == 0) {
      cout << fights << " 2\n";
      return 0;
    }
    if (p2 == 0) {
      cout << fights << " 1\n";
      return 0;
    } else {
      fights++;
      k1--;
      k2--;
      int top1 = p1 / pow100[k1];
      int top2 = p2 / pow100[k2];
      p1 %= pow100[k1];
      p2 %= pow100[k2];
      if (top1 > top2) {
        p1 *= 100;
        p1 += top2;
        p1 *= 100;
        p1 += top1;
        k1 += 2;
      } else {
        p2 *= 100;
        p2 += top1;
        p2 *= 100;
        p2 += top2;
        k2 += 2;
      }
    }
  }
  return 0;
}
