#include <bits/stdc++.h>
using namespace std;
int a[1111], b[1111];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1, _b = n; i <= _b; i++) scanf("%d", &a[i]);
  for (int i = 1, _b = m; i <= _b; i++) scanf("%d", &b[i]);
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1);
  int res = max(a[n], a[1] * 2);
  for (int i = 1, _b = m; i <= _b; i++) {
    if (res >= b[i]) {
      printf("-1\n");
      return 0;
    }
  }
  cout << res << endl;
  return 0;
}
