#include <bits/stdc++.h>
using namespace std;
const int N = 200;
vector<int> a, b;
int main(void) {
  int n, m, temp;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    a.push_back(temp);
  }
  for (int i = 0; i < m; i++) {
    cin >> temp;
    b.push_back(temp);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int mina = a[0], minb = b[0], maxa = a[a.size() - 1], maxb = b[b.size() - 1];
  if (maxa >= minb) {
    cout << -1;
  } else {
    int ans = max(2 * mina, maxa);
    if (ans >= minb)
      cout << -1;
    else
      cout << ans;
  }
}
