#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  int i = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
  }
  sort(a, a + n);
  sort(b, b + m);
  if (b[0] <= a[n - 1] or a[n - 1] < 0 or 2 * a[0] >= b[0]) {
    cout << -1 << endl;
  } else if (a[0] == a[n - 1]) {
    cout << 2 * a[0] << endl;
  } else {
    cout << max(2 * a[0], a[n - 1]) << endl;
  }
}
