#include <bits/stdc++.h>
using namespace std;
int n, k, a, b;
queue<int> x, y;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> k;
    x.push(k);
  }
  cin >> b;
  for (int i = 0; i < b; i++) {
    cin >> k;
    y.push(k);
  }
  for (int i = 0; i < 10000; i++) {
    if (x.empty()) {
      cout << i << " " << 2 << "\n";
      return 0;
    } else if (y.empty()) {
      cout << i << " " << 1 << "\n";
      return 0;
    } else {
      a = x.front(), x.pop();
      b = y.front(), y.pop();
      if (a > b)
        x.push(b), x.push(a);
      else
        y.push(a), y.push(b);
    }
  }
  cout << -1 << "\n";
}
