#include <bits/stdc++.h>
using namespace std;
int n, m;
int counter = 0;
int ans = 0;
vector<int> L[500000];
bool visited[500000];
bool cat[500000];
int main() {
  int a, b, k1, k2;
  deque<int> q1, q2, t1, t2;
  set<pair<deque<int>, deque<int> > > st;
  scanf("%d", &n);
  scanf("%d", &k1);
  for (int i = 1; i <= k1; i++) {
    cin >> a;
    q1.push_back(a);
  }
  scanf("%d", &k2);
  for (int i = 1; i <= k2; i++) {
    cin >> a;
    q2.push_back(a);
  }
  int fight = 0;
  int x, y;
  t1 = q1;
  t2 = q2;
  bool loop = false;
  int winner = 0;
  st.insert(make_pair(q1, q2));
  while (true) {
    if (q1.empty()) {
      winner = 2;
      break;
    }
    if (q2.empty()) {
      winner = 1;
      break;
    }
    x = q1.front();
    y = q2.front();
    q1.pop_front();
    q2.pop_front();
    if (x > y)
      q1.push_back(y), q1.push_back(x);
    else
      q2.push_back(x), q2.push_back(y);
    fight++;
    st.insert(make_pair(q1, q2));
    if (t1 == q1 and t2 == q2 or (t2 == q1 and t1 == q2)) {
      loop = true;
      break;
    }
    if (st.size() != fight + 1) {
      loop = true;
      break;
    }
  }
  if (!loop)
    cout << fight << " " << winner << endl;
  else
    cout << -1 << endl;
  return 0;
}
