#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n = 0, k1 = 0, k2 = 0;
  cin >> n >> k1;
  vector<int> p1(k1);
  for (int i = 0; i < k1; i++) cin >> p1[i];
  cin >> k2;
  vector<int> p2(k2);
  for (int i = 0; i < k2; i++) cin >> p2[i];
  for (int game = 1; game < 1000; game++) {
    int cur1 = p1[0], cur2 = p2[0];
    p1.erase(p1.begin());
    p2.erase(p2.begin());
    if (cur1 > cur2) {
      p1.push_back(cur2);
      p1.push_back(cur1);
    } else {
      p2.push_back(cur1);
      p2.push_back(cur2);
    }
    if (p1.size() == 0) {
      cout << game << ' ' << 2;
      return 0;
    } else if (p2.size() == 0) {
      cout << game << ' ' << 1;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
