#include <bits/stdc++.h>
using namespace std;
double st, tl = 1.8;
bool good() { return (clock() - st) / CLOCKS_PER_SEC < tl; }
void solve() {
  st = clock();
  deque<int> a, b;
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    b.push_back(x);
  }
  int w = 0, ans = 0;
  bool e = 0;
  while (good()) {
    if ((int)(a).size() == 0) {
      w = 2;
      e = 1;
      break;
    } else if ((int)(b).size() == 0) {
      w = 1;
      e = 1;
      break;
    }
    int n = a.front();
    int m = b.front();
    a.pop_front();
    b.pop_front();
    if (n > m) {
      a.push_back(m);
      a.push_back(n);
    } else {
      b.push_back(n);
      b.push_back(m);
    }
    ans++;
  }
  if (!e)
    cout << -1 << endl;
  else
    cout << ans << " " << w << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
