#include <bits/stdc++.h>
const int INF = (int)1e9;
using namespace std;
int n, m;
map<pair<vector<int>, vector<int> >, int> occ;
vector<int> a, b;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  a.resize(m);
  for (int i = 0; i < m; i++) cin >> a[i];
  cin >> m;
  b.resize(m);
  for (int i = 0; i < m; i++) cin >> b[i];
  int cnt = 0;
  while (occ.find(make_pair(a, b)) == occ.end()) {
    occ[make_pair(a, b)]++;
    if (a[0] > b[0]) {
      a.push_back(b[0]);
      a.push_back(a[0]);
    } else {
      b.push_back(a[0]);
      b.push_back(b[0]);
    }
    a.erase(a.begin());
    b.erase(b.begin());
    cnt++;
    if (a.empty()) {
      cout << cnt << ' ' << 2 << '\n';
      return 0;
    } else if (b.empty()) {
      cout << cnt << ' ' << 1 << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}
