#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  long long x1, x2;
  deque<long long> q1, q2;
  long long ns = 0;
  cin >> x1;
  for (long long i = 0; i < x1; i++) {
    long long y;
    cin >> y;
    q1.push_back(y);
  }
  cin >> x2;
  for (long long i = 0; i < x2; i++) {
    long long y;
    cin >> y;
    q2.push_back(y);
  }
  while (1) {
    if (ns > 100001) {
      cout << -1;
      break;
    }
    if (q1.empty()) {
      cout << ns << " " << 2;
      break;
    }
    if (q2.empty()) {
      cout << ns << " " << 1;
      break;
    }
    long long x1 = q1.front(), x2 = q2.front();
    if (x1 > x2) {
      q2.pop_front();
      q1.pop_front();
      q1.push_back(x2);
      q1.push_back(x1);
    } else {
      q2.pop_front();
      q1.pop_front();
      q2.push_back(x1);
      q2.push_back(x2);
    }
    ns++;
  }
}
