#include <bits/stdc++.h>
int main() {
  int n, m, min_m, max_n, min_n, x;
  scanf("%d%d", &n, &m);
  scanf("%d", &max_n);
  min_n = max_n;
  n--;
  while (n--) {
    scanf("%d", &x);
    if (x > max_n) {
      max_n = x;
    } else if (x < min_n) {
      min_n = x;
    }
  }
  scanf("%d", &min_m);
  m--;
  while (m--) {
    scanf("%d", &x);
    if (x < min_m) {
      min_m = x;
    }
  }
  if (min_m <= max_n) {
    printf("-1");
    return 0;
  }
  int t = max_n;
  while (t < min_m) {
    if (2 * min_n <= t) {
      printf("%d", t);
      return 0;
    }
    t++;
  }
  printf("-1");
}
