#include <bits/stdc++.h>
using namespace std;
queue<int> q1, q2;
int n, k1, k2;
int main() {
  cin >> n;
  cin >> k1;
  int t;
  for (int i = 1; i <= k1; i++) scanf("%d", &t), q1.push(t);
  cin >> k2;
  for (int i = 1; i <= k2; i++) cin >> t, q2.push(t);
  for (int cnt = 1; cnt <= (int)1e6; cnt++) {
    int a = q1.front();
    q1.pop();
    int b = q2.front();
    q2.pop();
    if (a > b)
      q1.push(b), q1.push(a);
    else
      q2.push(a), q2.push(b);
    if (q1.empty() || q2.empty()) {
      cout << cnt;
      printf(" %c\n", q1.empty() ? '2' : '1');
      return 0;
    }
  }
  puts("-1");
}
