#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, SZ = 300007;
int a[SZ];
bool check(int num, int &n) {
  bool f = 0;
  for (int i = 0; i < n; i++) {
    f |= (2 * a[i] <= num);
    if (a[i] > num) return 0;
  }
  return f;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long num = -1;
  vector<int> v(m);
  for (int i = 0; i < m; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  num = v[0] - 1;
  long long ans = -1;
  for (int i = 1; i <= num; i++) {
    if (check(i, n)) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
