#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[109], arr1[109], maxx = -1, minn = 999, minn2 = 999;
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &arr1[i]);
  }
  for (int i = 1; i <= n; i++) {
    maxx = max(maxx, arr[i]);
    minn = min(minn, arr[i]);
  }
  for (int i = 1; i <= m; i++) {
    minn2 = min(minn2, arr1[i]);
  }
  int d;
  d = minn * 2;
  if (maxx < minn2 && d < minn2) {
    if (maxx >= d)
      cout << maxx << endl;
    else
      cout << d << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
