#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string str, str2;
  long long size, elm, tc, lim, n, m;
  tc = 1;
  while (tc--) {
    cin >> n >> m;
    long long max = -1, min = 101;
    for (long long x = 0; x < n; x++) {
      cin >> elm;
      max = std::max(max, elm);
      min = std::min(min, elm);
    }
    long long min2 = 101;
    for (long long x = 0; x < m; x++) {
      cin >> elm;
      min2 = std::min(min2, elm);
    }
    if (min2 - 1 >= max && min * 2 <= min2 - 1) {
      cout << std::max(min * 2, max);
    } else
      cout << -1;
  }
  return 0;
}
