#include <bits/stdc++.h>
using namespace std;
void TLEsol();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) TLEsol();
  return 0;
}
void TLEsol() {
  long long n, m, p = INT_MIN, q = INT_MAX, r;
  cin >> n >> m;
  vector<long long> shi(n), glt(m);
  for (auto& a : shi) {
    cin >> a;
    p = max(p, a);
    q = min(q, a);
  }
  r = max(p, 2 * q);
  for (auto& a : glt) {
    cin >> a;
    if (a <= r) {
      r = -1;
    }
  }
  cout << r << endl;
}
