#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int min_pos, max_pos;
  int min_tle = (1 << 30);
  min_pos = (1 << 30);
  max_pos = 0;
  cin >> n >> m;
  for (int i = 0, temp; i < n; ++i) {
    cin >> temp;
    min_pos = min(min_pos, temp);
    max_pos = max(max_pos, temp);
  }
  for (int i = 0, temp; i < m; ++i) {
    cin >> temp;
    min_tle = min(temp, min_tle);
  }
  int v = min_tle - 1;
  while (v >= max_pos && 2 * min_pos <= v) v--;
  v++;
  if (v == min_tle || max_pos >= min_tle)
    cout << -1 << endl;
  else
    cout << v << endl;
  return 0;
}
