#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline int toLL(string s) {
  long long v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
int main() {
  int n;
  cin >> n;
  deque<int> deq1, deq2;
  int k, t;
  cin >> k;
  for (long i = (0); i < (k); ++i) {
    cin >> t;
    deq1.push_back(t);
  }
  cin >> k;
  for (long i = (0); i < (k); ++i) {
    cin >> t;
    deq2.push_back(t);
  }
  int f = -1;
  long cnt = 0;
  for (long i = (0); i < (10000000); ++i) {
    if (deq1.empty()) {
      f = 2;
      break;
    } else if (deq2.empty()) {
      f = 1;
      break;
    }
    int p1 = deq1.front();
    int p2 = deq2.front();
    deq1.pop_front();
    deq2.pop_front();
    if (p1 > p2) {
      deq1.push_back(p2);
      deq1.push_back(p1);
    } else {
      deq2.push_back(p1);
      deq2.push_back(p2);
    }
    cnt++;
  }
  if (f == -1)
    cout << f << endl;
  else {
    cout << cnt << " " << f << endl;
  }
  return 0;
}
