#include <bits/stdc++.h>
using namespace std;
int a[14], b[14];
int main() {
  int x, y, n, i, s, t, f = 0, l = 0;
  cin >> n;
  cin >> x;
  queue<int> q;
  queue<int> qc;
  queue<int> qe;
  for (i = 0; i < x; i++) {
    cin >> a[i];
    q.push(a[i]);
  }
  cin >> y;
  for (i = 0; i < y; i++) {
    cin >> b[i];
    qe.push(b[i]);
  }
  while (!q.empty() && !qe.empty() && l < 1000000) {
    if (q.front() > qe.front()) {
      s = qe.front();
      t = q.front();
      qe.pop();
      q.pop();
      q.push(s);
      q.push(t);
    } else {
      s = q.front();
      t = qe.front();
      q.pop();
      qe.pop();
      qe.push(s);
      qe.push(t);
    }
    l++;
  }
  if (l >= 1000000)
    cout << "-1";
  else {
    cout << l;
    if (q.empty())
      printf(" 2");
    else
      printf(" 1");
  }
  return 0;
}
