#include <bits/stdc++.h>
using namespace std;
int n, m, a;
vector<int> v, s;
void solver() {
  int t1 = v[0];
  int t2 = v.back();
  int tl = max(2 * v[0], t2);
  (tl < s[0]) ? cout << tl << '\n' : cout << -1 << '\n';
}
void start() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  for (int i = 0; i < m; i++) {
    cin >> a;
    s.push_back(a);
  }
  sort(v.begin(), v.end());
  sort(s.begin(), s.end());
  solver();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  start();
  return 0;
}
