#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, flag, n, i, m, arr1[110], sol, arr2[110];
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> arr1[i];
  for (i = 0; i < m; i++) cin >> arr2[i];
  sort(arr1, arr1 + n);
  sort(arr2, arr2 + m);
  flag = 0;
  sol = arr1[n - 1];
  a = 2 * arr1[0];
  sol = max(a, sol);
  if (arr2[0] <= sol) flag = 1;
  if (flag == 0)
    printf("%d\n", sol);
  else
    printf("-1\n");
  return 0;
}
