#include <bits/stdc++.h>
using namespace std;
long long ele[11];
int n, t;
int k1, k2;
queue<int> s1, s2;
map<long long, bool> Ex;
long long pl(queue<int> s) {
  long long p = 0;
  int i = 0;
  while (!s.empty()) {
    p += s.front() * 1LL * ele[i];
    s.pop();
    i++;
  }
  return p;
}
int main() {
  scanf("%d", &n);
  int v;
  scanf("%d", &k1);
  for (int i = 0; i < k1; i++) scanf("%d", &v), s1.push(v);
  scanf("%d", &k2);
  for (int i = 0; i < k2; i++) scanf("%d", &v), s2.push(v);
  for (long long i = 0, p = 1; i < 11; i++, p *= 11) ele[i] = p;
  int t = 0;
  while (1) {
    int u = s1.front();
    int v = s2.front();
    s1.pop();
    s2.pop();
    t++;
    if (u > v) {
      s1.push(v);
      s1.push(u);
    } else {
      s2.push(u);
      s2.push(v);
    }
    if (s1.empty()) {
      printf("%d %d", t, 2);
      return 0;
    }
    if (s2.empty()) {
      printf("%d %d", t, 1);
      return 0;
    }
    if (Ex[pl(s1)] && t > 100) {
      printf("-1");
      return 0;
    }
    Ex[pl(s1)] = 1;
  }
}
