#include <bits/stdc++.h>
using namespace std;
int n, m, a[100], b[100];
int main() {
  int mina = 101, maxa = -1, minb = 101;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (maxa < a[i]) maxa = a[i];
    if (mina > a[i]) mina = a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    if (minb > b[i]) minb = b[i];
  }
  if (minb <= maxa || mina * 2 >= minb) {
    cout << -1;
    goto ex;
  } else {
    for (int i = mina; i <= maxa * 2; i++)
      if (i >= mina * 2 && i >= maxa) {
        cout << i;
        goto ex;
      }
  };
ex:
  return 0;
}
