#include <bits/stdc++.h>
using namespace std;
int n, m, x;
int acmaxx, acminn = 9999, tleminn = 9999;
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    acmaxx = max(x, acmaxx);
    acminn = min(x, acminn);
  }
  for (int i = 1; i <= m; i++) {
    cin >> x;
    tleminn = min(x, tleminn);
  }
  if (tleminn <= acmaxx || tleminn <= acminn * 2) {
    cout << -1 << endl;
    return 0;
  }
  cout << max(acminn * 2, acmaxx) << endl;
  return 0;
}
