#include <bits/stdc++.h>
using namespace std;
long long int n, m, k, g, mx, mn, res, c, x, y, z, w, p, q, r, l, s, t;
void solve() {
  cin >> n >> m;
  vector<long long int> a(n), b(m);
  long long int amin, amax, bmin;
  amin = bmin = 10000000;
  amax = 0;
  for (auto &x : a) {
    cin >> x;
    amin = min(amin, x);
    amax = max(amax, x);
  }
  for (auto &x : b) {
    cin >> x;
    bmin = min(bmin, x);
  }
  long long int v;
  v = max(amin * 2, amax);
  if (v < bmin)
    cout << v << endl;
  else
    cout << -1 << endl;
}
int main() {
  auto start_time = clock();
  cerr << setprecision(3) << fixed;
  cout << setprecision(10) << fixed;
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  t = 1;
  for (long long int ca = 0; ca < t; ca++) {
    solve();
  }
  auto end_time = clock();
  cerr << "Execution time: "
       << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
}
