#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int k1, k2, w;
  scanf("%d", &k1);
  queue<int> q1;
  queue<int> q2;
  for (int i = 0; i < k1; i++) {
    scanf("%d", &w);
    q1.push(w);
  }
  scanf("%d", &k2);
  for (int i = 0; i < k2; i++) {
    scanf("%d", &w);
    q2.push(w);
  }
  int count = 0;
  while (!q1.empty() && !q2.empty() && count < 1000000) {
    int x = q1.front();
    q1.pop();
    int y = q2.front();
    q2.pop();
    if (x > y) {
      q1.push(y);
      q1.push(x);
    } else {
      q2.push(x);
      q2.push(y);
    }
    count++;
  }
  int ans;
  if (q1.empty())
    ans = 2;
  else
    ans = 1;
  if (count == 1000000)
    printf("-1\n");
  else
    printf("%d %d\n", count, ans);
}
