#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k1, k2, l, k = 0, e = 0, o = 0, o1 = 0;
  vector<int> k11, k21, k41, k31;
  cin >> n >> k1;
  for (int i = 0; i < k1; i++) {
    cin >> l;
    k11.push_back(l);
  }
  cin >> k2;
  for (int i = 0; i < k2; i++) {
    cin >> l;
    k21.push_back(l);
  }
  while (true) {
    if (k11.size() != 0 && k21.size() != 0) {
      if (k11[0] < k21[0]) {
        k21.push_back(k11[0]);
        for (int i = 1; i < k21.size(); i++) {
          k41.push_back(k21[i]);
        }
        k41.push_back(k21[0]);
        k21 = k41;
        k41.clear();
        k11.erase(k11.begin(), k11.begin() + 1);
      } else if (k11[0] > k21[0]) {
        k11.push_back(k21[0]);
        for (int i = 1; i < k11.size(); i++) {
          k41.push_back(k11[i]);
        }
        k41.push_back(k11[0]);
        k11 = k41;
        k41.clear();
        k21.erase(k21.begin(), k21.begin() + 1);
      }
    } else {
      if (k11.size() == 0) {
        e = 2;
      } else if (k21.size() == 0) {
        e = 1;
      }
      break;
    }
    k++;
    if (k > 2000000) {
      cout << -1;
      return 0;
    }
  }
  cout << k << ' ' << e;
  return 0;
}
