#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k;
  cin >> n >> m;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  int b[m];
  for (i = 0; i < m; i++) cin >> b[i];
  sort(a, a + n);
  sort(b, b + m);
  int f = 1;
  if (n == 1) {
    if (a[0] * 2 < b[0])
      cout << 2 * a[0];
    else
      cout << -1;
  } else {
    if (a[n - 1] >= b[0])
      f = 0;
    else if (a[0] * 2 >= b[0])
      f = 0;
    if (f == 1) {
      if (a[0] * 2 > a[n - 1])
        cout << a[0] * 2;
      else
        cout << a[n - 1];
    } else
      cout << -1;
  }
  return 0;
}
