#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, corr[101], wrong[101], v;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> corr[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> wrong[j];
  }
  int p = 0;
  for (int k = 0; k < n; k++) {
    if (corr[k] >= p) {
      p = corr[k];
    }
  }
  int min_corr = 100000;
  for (int q = 0; q < n; q++) {
    if (corr[q] > min_corr) {
      min_corr = min_corr;
    } else
      min_corr = corr[q];
  }
  if (min_corr * 2 > p)
    v = min_corr * 2;
  else
    v = p;
  int wr = 0;
  for (int r = 0; r < m; r++) {
    if (wrong[r] <= v) {
      wr++;
      break;
    }
  }
  if (wr == 0)
    cout << v << endl;
  else
    cout << -1 << endl;
  return 0;
}
