#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int mn1 = 999, mx1 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mn1 = min(mn1, a[i]);
    mx1 = max(mx1, a[i]);
  }
  vector<int> b(m);
  int mn2 = 999, mx2 = 0;
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    mn2 = min(mn2, b[i]);
    mx2 = max(mx2, b[i]);
  }
  if (mx1 >= mn2)
    cout << -1;
  else {
    if (mn1 * 2 <= mx1)
      cout << mx1;
    else {
      if (mn1 * 2 >= mx1 && mn1 * 2 < mn2)
        cout << mn1 * 2;
      else
        cout << -1;
    }
  }
  return 0;
}
