#include <bits/stdc++.h>
using namespace std;
int dis(pair<int, int> p1, pair<int, int> p2) {
  return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int n;
  cin >> n;
  deque<int> s1;
  deque<int> s2;
  int n1, n2;
  cin >> n1;
  for (int i = 0; i < n1; i++) {
    int v;
    cin >> v;
    s1.push_back(v);
  }
  cin >> n2;
  for (int i = 0; i < n2; i++) {
    int v;
    cin >> v;
    s2.push_back(v);
  }
  for (int i = 1; i < 1e6; i++) {
    int v1 = s1.front();
    int v2 = s2.front();
    s1.pop_front();
    s2.pop_front();
    if (v1 > v2) {
      s1.push_back(v2);
      s1.push_back(v1);
    } else {
      s2.push_back(v1);
      s2.push_back(v2);
    }
    if (s1.empty()) {
      cout << i << " 2" << endl;
      return 0;
    } else if (s2.empty()) {
      cout << i << " 1" << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
