#include <bits/stdc++.h>
using namespace std;
int main() {
  queue<int> s1, s2;
  map<queue<int>, int> p1, p2;
  int n;
  cin >> n;
  int k1, k2, i, a, b;
  cin >> k1;
  for (i = 0; i < k1; i++) {
    cin >> a;
    s1.push(a);
  }
  cin >> k2;
  for (i = 0; i < k2; i++) {
    cin >> b;
    s2.push(b);
  }
  int f = 0, chances = 0;
  p1.insert(make_pair(s1, 1));
  p2.insert(make_pair(s2, 1));
  while (!s1.empty() && !s2.empty()) {
    int aa = s1.front();
    int bb = s2.front();
    if (aa > bb) {
      s1.pop();
      s2.pop();
      s1.push(bb);
      s1.push(aa);
    } else {
      s1.pop();
      s2.pop();
      s2.push(aa);
      s2.push(bb);
    }
    chances++;
    if (chances >= 100000) {
      f = 1;
      break;
    }
    if (p1.find(s1) != p1.end() && p2.find(s2) != p2.end()) {
      f = 1;
      break;
    }
  }
  if (f == 1)
    cout << "-1\n";
  else if (s1.empty())
    cout << chances << " 2\n";
  else
    cout << chances << " 1\n";
  return 0;
}
