#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i;
  cin >> n >> m;
  vector<int> v1;
  vector<int> v2;
  for (i = 0; i < n; i++) {
    int p;
    cin >> p;
    v1.push_back(p);
  }
  for (i = 0; i < m; i++) {
    int p;
    cin >> p;
    v2.push_back(p);
  }
  vector<int>::iterator it1;
  vector<int>::iterator it2;
  vector<int>::iterator it3;
  it1 = max_element(v1.begin(), v1.end());
  it2 = min_element(v2.begin(), v2.end());
  it3 = max_element(v2.begin(), v2.end());
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  if (*it1 >= *it3) {
    cout << "-1";
    return 0;
  }
  int j;
  for (i = *it1; i < *it3; i++) {
    int c = 0, d = 0, e = 0;
    for (j = 0; j < n; j++) {
      if (i >= v1[j]) c++;
      if (i >= (2 * v1[j])) d++;
    }
    if (d != 0 && c == n) {
      for (j = 0; j < m; j++) {
        if (i >= v2[j]) {
          cout << "-1";
          return 0;
        }
      }
      cout << i;
      return 0;
    }
  }
  cout << "-1";
}
