#include <bits/stdc++.h>
using namespace std;
int main() {
  ios ::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> N(n), M(m);
  for (auto &i : N) {
    cin >> i;
  }
  for (auto &i : M) {
    cin >> i;
  }
  sort(N.begin(), N.end());
  sort(M.begin(), M.end());
  int TL = max(2 * N[0], N.back());
  if (N[0] * 2 <= TL and TL < M[0]) {
    cout << TL;
  } else {
    cout << "-1";
  }
}
