#include <bits/stdc++.h>
using namespace std;
deque<int> a, b;
int main() {
  int x, y, i, j, k, n, m, k1, k2;
  cin >> n;
  cin >> k1;
  for (i = 0; i < k1; ++i) {
    cin >> x;
    a.push_back(x);
  }
  cin >> k2;
  for (i = 0; i < k2; ++i) {
    cin >> x;
    b.push_back(x);
  }
  k = -1;
  m = 0;
  for (i = 0; i < 4000000; ++i) {
    if (a.empty() || b.empty()) {
      k = i;
      if (a.empty())
        m = 2;
      else
        m = 1;
      break;
    }
    x = a.front();
    y = b.front();
    a.pop_front();
    b.pop_front();
    if (x > y) {
      a.push_back(y);
      a.push_back(x);
    } else {
      b.push_back(x);
      b.push_back(y);
    }
  }
  if (k == -1) {
    cout << "-1";
  } else {
    cout << k << ' ' << m;
  }
  return 0;
}
