#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
queue<int> s1, s2, r1, r2;
set<pair<long long, long long> > Q;
int main() {
  int n;
  long long a, b;
  a = b = 0;
  scanf("%d", &n);
  int k1;
  scanf("%d", &k1);
  for (int i = 0; i < k1; i++) {
    int x;
    scanf("%d", &x);
    a = a * 10 + x;
    s1.push(x);
  }
  scanf("%d", &k1);
  for (int i = 0; i < k1; i++) {
    int x;
    scanf("%d", &x);
    b = b * 10 + x;
    r1.push(x);
  }
  Q.insert(make_pair(a, b));
  long long ans = 0;
  while (!s1.empty() && !r1.empty()) {
    long long l1 = s1.size(), l2 = r1.size();
    long long po = 1;
    for (int i = 0; i < l1; i++) {
      po *= 10;
    }
    a %= po;
    po = 1;
    for (int i = 0; i < l2; i++) {
      po *= 10;
    }
    b %= po;
    int t1 = s1.front(), t2 = r1.front();
    s1.pop();
    r1.pop();
    if (t1 > t2) {
      s1.push(t2);
      s1.push(t1);
      a = a * 10 + t2;
      a = a * 10 + t1;
    } else {
      r1.push(t1);
      r1.push(t2);
      b = b * 10 + t1;
      b = b * 10 + t2;
    }
    if (((Q).find(make_pair(a, b)) != (Q).end())) {
      printf("-1\n");
      return 0;
    }
    Q.insert(make_pair(a, b));
    ans++;
  }
  if (s1.empty()) {
    printf("%I64d 2\n", ans);
    return 0;
  }
  printf("%I64d 1\n", ans);
  return 0;
}
