#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b, i, v;
  bool flag = false;
  cin >> n >> m;
  vector<int> correct;
  vector<int> wrong;
  for (i = 0; i < n; i++) {
    cin >> a;
    correct.push_back(a);
  }
  for (i = 0; i < m; i++) {
    cin >> b;
    wrong.push_back(b);
  }
  int min_wrong = *(min_element(wrong.begin(), wrong.end()));
  int max_correct = *(max_element(correct.begin(), correct.end()));
  sort(correct.begin(), correct.end());
  vector<int> range;
  for (i = max_correct; i < min_wrong; i++) range.push_back(i);
  int l = range.size();
  if (max_correct > min_wrong)
    v = -1;
  else {
    for (i = 0; i < l; i++) {
      if (range[i] >= 2 * correct[0]) {
        flag = true;
        v = range[i];
        break;
      }
    }
    if (flag == false) v = -1;
  }
  cout << v;
}
