#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, num, maxs = INT_MIN, mins = INT_MAX, mins2 = INT_MAX;
  cin >> n >> m;
  vector<int> v1;
  vector<int> v2;
  for (int i = 0; i < n; i++) {
    cin >> num;
    v1.push_back(num);
    maxs = max(maxs, num);
    mins2 = min(mins2, num);
  }
  for (int i = 0; i < m; i++) {
    cin >> num;
    v2.push_back(num);
    if (num <= maxs) {
      cout << "-1";
      return 0;
    }
    mins = min(mins, num);
  }
  for (int i = 0; i < n; i++) {
    if (2 * v1[i] <= maxs) {
      cout << maxs;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (2 * mins2 <= mins - 1) {
      cout << 2 * mins2;
      return 0;
    }
    if (2 * v1[i] <= mins - 1) {
      cout << mins - 1;
      return 0;
    }
  }
  cout << "-1";
  return 0;
}
