#include <bits/stdc++.h>
using namespace std;
int a[100], b[100];
int main() {
  int n, m, mx, mn, mn1, ans = -1;
  cin >> n;
  cin >> m;
  cin >> a[0];
  mx = a[0];
  mn1 = a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
    mn1 = min(mn1, a[i]);
  }
  cin >> b[0];
  mn = b[0];
  for (int j = 1; j < m; j++) {
    cin >> b[j];
    mn = min(mn, b[j]);
  }
  if (mx < mn) {
    for (int j = mx; j < mn; j++)
      if (j >= 2 * mn1) {
        ans = j;
        break;
      }
  }
  cout << ans << endl;
  return 0;
}
