#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int pass[n];
  int fail[m];
  bool flag = false;
  for (int i = 0; i < n; i++) {
    cin >> pass[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> fail[i];
  }
  sort(pass, pass + n);
  sort(fail, fail + m);
  int tl = fail[0] - 1;
  int min = 2 * pass[0];
  vector<int> vc;
  for (int i = pass[n - 1]; i <= tl; i++) {
    vc.push_back(i);
  }
  sort(vc.begin(), vc.end());
  for (int i = 0; i < vc.size(); i++) {
    if (vc[i] >= min && vc[i] >= pass[n - 1] && vc[i] < fail[0]) {
      flag = true;
      cout << vc[i];
      break;
    }
  }
  if (!flag) {
    cout << -1;
  }
}
