#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k1, k2;
  cin >> n;
  cin >> k1;
  deque<int> a1, a2;
  vector<int> a;
  for (int i = 0; i < k1; ++i) {
    int x;
    cin >> x;
    a1.push_back(x);
    a.push_back(x);
  }
  cin >> k2;
  for (int i = 0; i < k2; ++i) {
    int x;
    cin >> x;
    a2.push_back(x);
    a.push_back(x);
  }
  map<int, int> m;
  sort(a.begin(), a.end());
  for (int i = 0; i < n; ++i) {
    m.insert(pair<int, int>(a[i], i + 1));
  }
  for (int i = 0; i < a1.size(); ++i) {
    a1[i] = m[a1[i]];
  }
  for (int i = 0; i < a2.size(); ++i) {
    a2[i] = m[a2[i]];
  }
  set<long long> s;
  int c = 0;
  while (!a1.empty() && !a2.empty()) {
    if (a1.front() > a2.front()) {
      a1.push_back(a2.front());
      a1.push_back(a1.front());
    } else {
      a2.push_back(a1.front());
      a2.push_back(a2.front());
    }
    a1.pop_front();
    a2.pop_front();
    c++;
    long long h = 0, p = 1;
    for (auto i : a1) {
      h += i * p;
      p *= n + 1;
    }
    p *= n + 1;
    for (auto i : a2) {
      h += i * p;
      p *= n + 1;
    }
    if (s.find(h) != s.end()) {
      cout << -1;
      return 0;
    } else {
      s.insert(h);
    }
  }
  cout << c << ' ';
  if (a1.empty()) cout << 2;
  if (a2.empty()) cout << 1;
  cout << '\n';
  return 0;
}
