#include <bits/stdc++.h>
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return ((a * b) / gcd(a, b)); }
using namespace std;
int main() {
  int i, j, k, l, m, n, a[1000], b[1000], max_a = 0, max_b = 0,
                                          min_a = INFINITY, min_b = INFINITY;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    max_a = max(a[i], max_a);
    min_a = min(a[i], min_a);
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
    max_b = max(b[i], max_b);
    min_b = min(b[i], min_b);
  }
  int x = max(2 * min_a, max_a);
  if (x < min_b) {
    cout << x;
  } else
    cout << -1;
}
