#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[1000] = {0}, b[1000] = {0}, cnt = 0, s;
  cin >> s;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> b[i];
  int maxi = max(n, m);
  for (int i = 1; i <= maxi; i++) {
    if (a[i] > b[i]) {
      a[n + 1] = b[i];
      a[n + 2] = a[i];
      n = n + 2;
      cnt++;
    }
    if (a[i] < b[i]) {
      b[m + 1] = a[i];
      b[m + 2] = b[i];
      m = m + 2;
      cnt++;
    }
    maxi = max(n, m);
    if (a[i] == 0) {
      cout << cnt - 1 << ' ' << 2;
      return 0;
    }
    if (b[i] == 0) {
      cout << cnt - 1 << ' ' << 1;
      return 0;
    }
    if (cnt > 105) {
      cout << -1;
      return 0;
    }
  }
  return 0;
}
