#include <bits/stdc++.h>
using namespace std;
deque<int> deck1;
deque<int> deck2;
int top1, top2;
int main() {
  int n, i;
  cin >> n;
  cin >> top1;
  long long int temp, count = 0;
  for (i = 0; i < top1; i++) {
    cin >> temp;
    deck1.push_back(temp);
  }
  cin >> top2;
  for (i = 0; i < top2; i++) {
    cin >> temp;
    deck2.push_back(temp);
  }
  while (!deck1.empty() && !deck2.empty()) {
    if (count > 110) {
      cout << -1 << endl;
      return 0;
    }
    count += 1;
    if (deck1.front() > deck2.front()) {
      deck1.push_back(deck2.front());
      deck1.push_back(deck1.front());
    } else {
      deck2.push_back(deck1.front());
      deck2.push_back(deck2.front());
    }
    deck1.pop_front();
    deck2.pop_front();
  }
  cout << count << " ";
  if (deck1.empty())
    cout << 2 << endl;
  else
    cout << 1 << endl;
  return 0;
}
