#include <bits/stdc++.h>
using namespace std;
int a[1000], b[1000];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 1; i < 5000; i++) {
    bool reservation = false;
    bool ac_passed = true;
    for (int j = 0; j < n; j++) {
      if (a[j] * 2 <= i) reservation = true;
      if (a[j] > i) ac_passed = false;
    }
    bool incor_failed = true;
    for (int j = 0; j < m; j++) {
      if (b[j] <= i) incor_failed = false;
    }
    if (incor_failed && ac_passed && reservation) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
