#include <bits/stdc++.h>
using namespace std;
const int N = (int)(3e3) + 7;
const int M = (int)(86400) + 7;
const long double eps = 1e-12;
const long long MOD = (long long)(1e9) + 7;
const long long INF = (long long)(1e9) + 7;
const long double PI = 3.14159265358979310000;
queue<int> p, v;
int main() {
  int n;
  cin >> n;
  int k1;
  cin >> k1;
  for (int i = 0; i < k1; ++i) {
    int first;
    cin >> first;
    p.push(first);
  }
  cin >> k1;
  for (int i = 0; i < k1; ++i) {
    int first;
    cin >> first;
    v.push(first);
  }
  int kol = 0;
  while (p.size() > 0 && v.size() > 0) {
    int x1 = p.front();
    p.pop();
    int x2 = v.front();
    v.pop();
    if (x1 > x2) {
      p.push(x2);
      p.push(x1);
    } else {
      v.push(x1);
      v.push(x2);
    }
    ++kol;
    if (kol == 4000000) return cout << -1 << endl, 0;
  }
  cout << kol << ' ';
  if (p.size() == 0)
    cout << 2 << endl;
  else
    cout << 1 << endl;
  return 0;
}
