#include <bits/stdc++.h>
using namespace std;
int a[105], b[105];
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    for (int i = 0; i < m; i++) scanf("%d", &b[i]);
    sort(a, a + n);
    sort(b, b + m);
    int ans = -1;
    int sta = max(a[n - 1], 2 * a[0]);
    if (sta < b[0]) {
      ans = sta;
      printf("%d\n", ans);
    } else {
      printf("-1\n");
    }
  }
}
