#include <bits/stdc++.h>
using namespace std;
int used[101];
int main() {
  int n, minn = 1 << 30, k, m, maxx = 0, mins = 1 << 30;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> k;
    if (k < minn) minn = k;
    if (k > maxx) maxx = k;
  }
  for (int i = 0; i < m; i++) {
    cin >> k;
    if (k < mins) mins = k;
  }
  int i = minn * 2, v = 0;
  while (i <= mins) {
    if (i < mins && i >= maxx) {
      v = 1;
      cout << i << endl;
      return 0;
    }
    i++;
  }
  cout << -1 << endl;
  return 0;
}
