#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k1, k2, x;
  int s1, s2;
  cin >> n;
  deque<int> one, two, f1, f2;
  cin >> k1;
  for (int i = 0; i < k1; ++i) {
    cin >> x;
    one.push_back(x);
  }
  cin >> k2;
  for (int i = 0; i < k2; ++i) {
    cin >> x;
    two.push_back(x);
  }
  f1 = one;
  f2 = two;
  int cnt = 0;
  while (1) {
    if (f1.empty()) {
      cout << cnt << " " << 2;
      return 0;
    } else if (f2.empty()) {
      cout << cnt << " " << 1;
      return 0;
    }
    s1 = f1.front();
    f1.pop_front();
    s2 = f2.front();
    f2.pop_front();
    if (s1 > s2) {
      f1.push_back(s2);
      f1.push_back(s1);
    } else {
      f2.push_back(s1);
      f2.push_back(s2);
    }
    ++cnt;
    if ((f1 == one && f2 == two) || (f2 == one && f1 == two) || cnt > 1000) {
      cout << -1;
      return 0;
    }
  }
}
