#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  int n, k1, k2;
  cin >> n >> k1;
  queue<int> q1, q2;
  while (k1--) {
    int x;
    cin >> x;
    q1.push(x);
  }
  cin >> k2;
  while (k2--) {
    int x;
    cin >> x;
    q2.push(x);
  }
  int l = 0;
  while (l < 500001) {
    l++;
    int x1 = q1.front(), x2 = q2.front();
    q2.pop(), q1.pop();
    if (x1 > x2) {
      q1.push(x2);
      q1.push(x1);
    } else {
      q2.push(x1);
      q2.push(x2);
    }
    if (q1.empty()) {
      cout << l << ' ' << 2, exit(0);
    }
    if (q2.empty()) {
      cout << l << ' ' << 1, exit(0);
    }
  }
  cout << -1;
}
