#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, min, max, i, t, f = 0;
  cin >> n >> m;
  cin >> min;
  max = min;
  for (i = 1; i < n; i++) {
    cin >> t;
    if (t > max)
      max = t;
    else if (t < min)
      min = t;
  }
  if (2 * min > max) max = 2 * min;
  for (i = 0; i < m; i++) {
    cin >> t;
    if (t <= max) f = 1;
  }
  if (f == 1)
    cout << "-1\n";
  else
    cout << max << endl;
  return 0;
}
