#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  vector<long long int> b(m);
  for (long long int i = 0; i < m; i++) cin >> b[i];
  long long int temp1 = *min_element(a.begin(), a.end());
  long long int temp2 = *max_element(a.begin(), a.end());
  long long int d = *min_element(b.begin(), b.end());
  if (max(temp2, 2 * temp1) < d)
    cout << max(temp2, 2 * temp1);
  else
    cout << -1;
}
