#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int N[n], M[m];
  for (int i = 0; i < n; ++i) cin >> N[i];
  for (int i = 0; i < m; ++i) cin >> M[i];
  int MIN = N[0];
  int MAX1 = N[0];
  for (int i = 0; i < n; ++i) {
    if (N[i] < MIN) MIN = N[i];
    if (N[i] > MAX1) MAX1 = N[i];
  }
  int MIN2 = M[0];
  for (int i = 0; i < m; ++i)
    if (MIN2 > M[i]) MIN2 = M[i];
  if (MIN2 > MAX1 and MIN * 2 < MIN2)
    if (MIN * 2 <= MAX1)
      cout << MAX1;
    else
      cout << MIN * 2;
  else
    cout << -1;
  cout << endl;
  return 0;
}
