#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> corr(n, 0);
  vector<int> wrong(m, 0);
  for (int i = 0; i < n; i++) {
    cin >> corr[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> wrong[i];
  }
  sort(corr.begin(), corr.end());
  sort(wrong.begin(), wrong.end());
  int low = corr[n - 1];
  int high = wrong[0];
  int v = low;
  if (v < high && 2 * corr[0] <= v) {
    cout << v << endl;
  } else if (v < high) {
    while (v < high) {
      if (2 * corr[0] <= v) {
        cout << v << endl;
        break;
      }
      v++;
    }
    if (v == high) cout << -1 << endl;
  } else
    cout << -1 << endl;
  return 0;
}
