#include <bits/stdc++.h>
using namespace std;
queue<int> s1, s2;
int main() {
  int n, k1, k2;
  cin >> n;
  cin >> k1;
  int a, b;
  for (int i = 0; i < k1; i++) {
    cin >> a;
    s1.push(a);
  }
  cin >> k2;
  for (int i = 0; i < k2; i++) {
    cin >> b;
    s2.push(b);
  }
  int ans = 0;
  while (!s1.empty() && !s2.empty() && ans < 2e5 + 10) {
    int t1 = s1.front();
    int t2 = s2.front();
    s1.pop();
    s2.pop();
    if (t1 > t2) {
      s1.push(t2);
      s1.push(t1);
    }
    if (t1 < t2) {
      s2.push(t1);
      s2.push(t2);
    }
    ans++;
  }
  if (s1.empty()) {
    cout << ans << " "
         << "2" << endl;
  }
  if (s2.empty()) {
    cout << ans << " "
         << "1" << endl;
  }
  if (ans == 2e5 + 10) cout << "-1" << endl;
  return 0;
}
