#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, c = 0, k;
  deque<int> q1, q2;
  cin >> n;
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> a;
    q1.push_front(a);
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> a;
    q2.push_front(a);
  }
  while (!q1.empty() && !q2.empty()) {
    if (q1.back() > q2.back()) {
      q1.push_front(q2.back());
      q1.push_front(q1.back());
      q1.pop_back();
      q2.pop_back();
    } else {
      q2.push_front(q1.back());
      q2.push_front(q2.back());
      q1.pop_back();
      q2.pop_back();
    }
    c++;
    if (c > 100000) return 0 & puts("-1");
  }
  cout << c << " ";
  if (q1.empty())
    cout << 2 << endl;
  else
    cout << 1 << endl;
}
