#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ac[n];
  int wr[m];
  int mini = 10000;
  int ans = -1;
  for (int i = 0; i < n; i++) scanf("%d", &ac[i]);
  for (int i = 0; i < m; i++) {
    scanf("%d", &wr[i]);
    mini = min(mini, wr[i]);
  }
  for (int i = 0; i < n; i++) {
    if (ac[i] < mini || 2 * ac[i] <= mini) {
      ans = max(ans, ac[i]);
    } else {
      cout << "-1";
      return 0;
    }
  }
  int fans = 0;
  sort(ac, ac + n);
  for (int i = 0; i < n; i++) {
    if (2 * ac[i] >= ans && 2 * ac[i] < mini) {
      cout << 2 * ac[i];
      return 0;
    } else if (2 * ac[i] <= ans && ans < mini) {
      cout << ans;
      return 0;
    }
  }
  if (ans) cout << "-1";
  return 0;
}
