#include <bits/stdc++.h>
using namespace std;
map<pair<queue<int>, queue<int> >, bool> mp;
int main(int argc, char const *argv[]) {
  int n, x, moves = 0;
  cin >> n;
  int k1;
  cin >> k1;
  queue<int> p1;
  for (int i = 0; i < k1; ++i) {
    cin >> x;
    p1.push(x);
  }
  int k2;
  cin >> k2;
  queue<int> p2;
  for (int i = 0; i < k2; ++i) {
    cin >> x;
    p2.push(x);
  }
  while (mp.find({p1, p2}) == mp.end() && (!p1.empty() && !p2.empty())) {
    mp.insert(make_pair(make_pair(p1, p2), true));
    int q = p1.front();
    p1.pop();
    int w = p2.front();
    p2.pop();
    if (q > w) {
      p1.push(w);
      p1.push(q);
    } else {
      p2.push(q);
      p2.push(w);
    }
    moves++;
  }
  if (p1.empty()) {
    cout << moves << " " << 2 << endl;
  } else if (p2.empty()) {
    cout << moves << " " << 1 << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
