#include <bits/stdc++.h>
using namespace std;
int const oo = 1e9;
int const mod = 1e9 + 7;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n, k1, k2;
  cin >> n >> k1;
  queue<int> q1, q2;
  for (int _ = 0; _ < int(k1); _++) {
    int k;
    cin >> k;
    q1.push(k);
  }
  cin >> k2;
  for (int _ = 0; _ < int(k2); _++) {
    int k;
    cin >> k;
    q2.push(k);
  }
  set<pair<string, string>> __set;
  int cont = 0;
  bool bul = 1;
  for (cont = 0; bul && !q1.empty() && !q2.empty(); cont++) {
    queue<int> tmp_q1;
    string s1 = "";
    while (!q1.empty()) {
      int k = q1.front();
      q1.pop();
      s1.push_back(char((k % 10) + '0'));
      tmp_q1.push(k);
    }
    swap(tmp_q1, q1);
    queue<int> tmp_q2;
    string s2 = "";
    while (!q2.empty()) {
      int k = q2.front();
      q2.pop();
      s2.push_back(char((k % 10) + '0'));
      tmp_q2.push(k);
    }
    swap(tmp_q2, q2);
    if (s1 > s2) swap(s1, s2);
    if (__set.count({s1, s2})) bul = 0;
    __set.insert({s1, s2});
    int k1 = q1.front(), k2 = q2.front();
    q1.pop(), q2.pop();
    if (k1 > k2) {
      q1.push(k2);
      q1.push(k1);
    } else {
      q2.push(k1);
      q2.push(k2);
    }
  }
  if (!bul)
    cout << "-1\n";
  else if (q1.empty())
    cout << cont << " 2\n";
  else
    cout << cont << " 1\n";
  return 0;
}
