#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int N = 5e5;
void solve() {
  long long int n;
  cin >> n;
  long long int steps = 0, flag = -1;
  deque<long long int> p1, p2;
  long long int n1;
  cin >> n1;
  while (n1--) {
    long long int a;
    cin >> a;
    p1.push_back(a);
  }
  long long int n2;
  cin >> n2;
  while (n2--) {
    long long int a;
    cin >> a;
    p2.push_back(a);
  }
  while (!p1.empty() & !p2.empty()) {
    steps++;
    long long int a = p1.front(), b = p2.front();
    p1.pop_front();
    p2.pop_front();
    if (a > b) {
      p1.push_back(b);
      p1.push_back(a);
      flag = 1;
    } else {
      p2.push_back(a);
      p2.push_back(b);
      flag = 2;
    }
    if (steps > 1e6) {
      flag = -1;
      break;
    }
  }
  if (flag == -1)
    cout << flag << endl;
  else
    cout << steps << " " << flag << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
