#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int c[n], w[m];
  int maxc = INT_MIN;
  int minc = INT_MAX;
  int minw = INT_MAX;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    if (c[i] > maxc) maxc = c[i];
    if (c[i] < minc) minc = c[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> w[i];
    if (w[i] < minw) minw = w[i];
  }
  for (int i = maxc; i < minw; i++) {
    if (i >= (2 * minc)) {
      cout << i;
      return 0;
    }
  }
  cout << "-1";
}
