#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, maxid = -9, minid = 9999999, miniw = 999999999;
  cin >> n >> m;
  int a[n], b[m];
  int f;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    maxid = max(maxid, a[i]);
    minid = min(minid, a[i]);
  }
  for (int i = 0; i < m; i++) {
    miniw = min(miniw, b[i]);
  }
  if (maxid >= miniw) {
    cout << -1;
    return 0;
  } else if (miniw > minid * 2 && minid * 2 >= maxid && maxid < miniw) {
    cout << minid * 2;
    return 0;
  } else if (minid * 2 < maxid) {
    cout << maxid;
  } else
    cout << -1;
}
