#include <bits/stdc++.h>
using namespace std;
queue<int> q1, q2;
map<queue<int>, queue<int> > m;
int main() {
  int n;
  cin >> n;
  int n1;
  cin >> n1;
  while (n1--) {
    int a;
    cin >> a;
    q1.push(a);
  }
  int n2;
  cin >> n2;
  while (n2--) {
    int b;
    cin >> b;
    q2.push(b);
  }
  m[q1] = q2;
  int cnt = 0;
  while (!q1.empty() && !q2.empty()) {
    int c1 = q1.front();
    q1.pop();
    int c2 = q2.front();
    q2.pop();
    if (c1 < c2) {
      q2.push(c1);
      q2.push(c2);
    } else {
      q1.push(c2);
      q1.push(c1);
    }
    cnt++;
    if (m.count(q1) && m[q1] == q2) {
      cnt = -1;
      break;
    } else
      m[q1] = q2;
  }
  if (cnt == -1)
    cout << -1 << endl;
  else {
    cout << cnt << " ";
    if (q1.empty())
      cout << 2;
    else
      cout << 1;
  }
  return 0;
}
