#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x, y;
  queue<int> A, B;
  cin >> x;
  for (int i = 0; i < x; ++i) {
    int c;
    cin >> c;
    A.push(c);
  }
  cin >> y;
  for (int i = 0; i < y; ++i) {
    int c;
    cin >> c;
    B.push(c);
  }
  int coun = 0;
  while (!A.empty() && !B.empty()) {
    int a, b;
    a = A.front();
    b = B.front();
    if (a > b) {
      A.push(b);
      A.push(a);
    } else {
      B.push(a);
      B.push(b);
    }
    A.pop();
    B.pop();
    coun++;
    if (coun > 1000000) {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << coun;
  if (A.empty())
    cout << " "
         << "2" << endl;
  else
    cout << " "
         << "1" << endl;
  return 0;
}
