#include <bits/stdc++.h>
using namespace std;
map<pair<string, string>, bool> M;
int main(void) {
  int n, k1, k2;
  scanf("%d", &n);
  scanf("%d", &k1);
  vector<int> a;
  for (int i = 0; i < k1; i++) {
    int temp;
    scanf("%d", &temp);
    a.push_back(temp);
  }
  scanf("%d", &k2);
  vector<int> b;
  for (int i = 0; i < k2; i++) {
    int temp;
    scanf("%d", &temp);
    b.push_back(temp);
  }
  int counter = 0;
  while (1) {
    string x = "", y = "";
    if (a.size() == 0) {
      printf("%d %d", counter, 2);
      return 0;
    } else if (b.size() == 0) {
      printf("%d %d", counter, 1);
      return 0;
    }
    for (int i = 0; i < a.size(); i++) {
      char c = a[i] + '0' - 1;
      x = x + c;
    }
    for (int i = 0; i < b.size(); i++) {
      char c = b[i] + '0' - 1;
      y = y + c;
    }
    if (M.find(make_pair(x, y)) != M.end()) {
      printf("-1");
      return 0;
    }
    M.insert(make_pair(make_pair(x, y), 1));
    int temp1 = a[0];
    int temp2 = b[0];
    a.erase(a.begin());
    b.erase(b.begin());
    if (temp1 > temp2) {
      a.push_back(temp2);
      a.push_back(temp1);
    } else {
      b.push_back(temp1);
      b.push_back(temp2);
    }
    counter++;
  }
  return 0;
}
