#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238;
bool DBG = false;
template <typename T, typename S>
std::ostream& operator<<(std::ostream& os, const std::pair<T, S>& p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vector) {
  for (size_t i = 0; i < vector.size(); ++i) {
    os << vector[i] << " ";
  }
  return os;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  queue<int> q1, q2;
  int n;
  int k1, k2;
  cin >> n;
  cin >> k1;
  vector<int> q1_start(k1);
  for (int i = 0; i < (int)(k1); ++i) {
    int a;
    cin >> a;
    q1.push(a);
    q1_start[i] = a;
  }
  cin >> k2;
  for (int i = 0; i < (int)(k2); ++i) {
    int a;
    cin >> a;
    q2.push(a);
  }
  int cnt = 0;
  set<pair<queue<int>, queue<int> > > s;
  while (true) {
    int a1 = q1.front();
    int a2 = q2.front();
    q1.pop();
    q2.pop();
    ++cnt;
    if (a1 < a2) {
      q2.push(a1);
      q2.push(a2);
    } else {
      q1.push(a2);
      q1.push(a1);
    }
    pair<queue<int>, queue<int> > p = make_pair(q1, q2);
    if (s.find(p) != s.end()) {
      cout << "-1";
      break;
    } else {
      s.insert(p);
    }
    if (q1.empty()) {
      cout << cnt << " 2";
      break;
    }
    if (q2.empty()) {
      cout << cnt << " 1";
      break;
    }
  }
  return 0;
}
