#include <bits/stdc++.h>
using namespace std;
int ga = 0, gb = 0;
int main() {
  int n, m;
  cin >> n >> m;
  int arr1[n];
  int arr2[m];
  for (int i = 0; i < n; i++) cin >> arr1[i];
  for (int j = 0; j < m; j++) {
    cin >> arr2[j];
  }
  sort(arr1, arr1 + n);
  sort(arr2, arr2 + m);
  int flag = 0;
  for (int i = arr1[n - 1]; i < arr2[0]; i++)
    if (arr1[0] * 2 <= i) {
      cout << i;
      flag = 1;
      break;
    }
  if (flag == 0) cout << -1;
}
