#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a, b, k, flag;
  queue<long long> now1, now2;
  cin >> n >> a;
  vector<long long> cart1(a);
  for (int i = 0; i < a; i++) {
    cin >> k;
    now1.push(k);
  }
  cin >> b;
  vector<long long> cart2(b);
  for (int i = 0; i < b; i++) {
    cin >> k;
    now2.push(k);
  }
  for (int i = 0; i < 10000000; i++) {
    if (now1.empty() == true) {
      cout << i << " 2";
      flag = 1;
      break;
    }
    if (now2.empty() == true) {
      cout << i << " 1";
      flag = 1;
      break;
    }
    if (now1.front() > now2.front()) {
      now1.push(now2.front());
      now1.push(now1.front());
    } else {
      now2.push(now1.front());
      now2.push(now2.front());
    }
    now2.pop();
    now1.pop();
    flag = 0;
  }
  if (flag == 0) {
    cout << "-1";
  }
  return 0;
}
