#include <bits/stdc++.h>
using namespace std;
int n;
int k1, k2;
int a[100000], b[100000];
bool k[38000000];
int s1, s2;
int e1, e2, v;
int cantor() {
  int ans = 0;
  int k[10], cnt = 0;
  for (int i = s1; i < e1; i++) k[cnt++] = a[i];
  for (int i = s2; i < e2; i++) k[cnt++] = b[i];
  for (int i = 0; i < n; i++) {
    int x = 0;
    int c = 1, m = 1;
    for (int j = i + 1; j < n; j++) {
      if (k[j] < k[i]) x++;
      m *= c;
      c++;
    }
    ans += x * m;
  }
  return ans;
}
int main() {
  cin >> n;
  cin >> k1;
  for (int i = 0; i < k1; i++) {
    cin >> a[i];
  }
  cin >> k2;
  for (int i = 0; i < k2; i++) {
    cin >> b[i];
  }
  s1 = s2 = 0;
  e1 = k1;
  e2 = k2;
  int cnt = 0;
  while (true) {
    cnt++;
    v = cantor() * 10 + e1 - s1;
    if (k[v]) {
      cout << -1 << endl;
      return 0;
    }
    k[v] = true;
    if (a[s1] > b[s2]) {
      a[e1++] = b[s2];
      a[e1++] = a[s1];
    } else {
      b[e2++] = a[s1];
      b[e2++] = b[s2];
    }
    s1++;
    s2++;
    if (s1 == e1) {
      cout << cnt << ' ' << 2 << endl;
      return 0;
    }
    if (s2 == e2) {
      cout << cnt << ' ' << 1 << endl;
      return 0;
    }
  }
  return 0;
}
