#include <bits/stdc++.h>
using namespace std;
int factorial(int n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int k1;
  cin >> k1;
  queue<int> q1, q2;
  for (int i = 0; i < k1; ++i) {
    int x;
    cin >> x;
    q1.push(x);
  }
  int k2;
  cin >> k2;
  for (int i = 0; i < k2; ++i) {
    int x;
    cin >> x;
    q2.push(x);
  }
  int lst = factorial(n + 1);
  int games = 0, player = 1;
  while (q1.size() != 0 and q2.size() != 0) {
    if (games > lst) {
      player = -1;
      break;
    }
    games += 1;
    if (q2.front() > q1.front()) {
      q2.push(q1.front());
      q2.push(q2.front());
      q1.pop();
      q2.pop();
      player = 2;
    } else {
      q1.push(q2.front());
      q1.push(q1.front());
      q1.pop();
      q2.pop();
      player = 1;
    }
  }
  if (player != -1) cout << games << " ";
  cout << player << "\n";
  return 0;
}
