#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, maxi = 0, mini = 1000, valid = 1, half = 0;
  cin >> n >> m;
  int* p = new int[n];
  int* w = new int[m];
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    maxi = max(maxi, p[i]);
  }
  for (int i = 0; i < m; i++) {
    cin >> w[i];
    mini = min(mini, w[i]);
  }
  for (int j = maxi; j < mini; j++) {
    for (int i = 0; i < n; i++) {
      if ((j / 2) >= p[i]) half = 1;
    }
    for (int i = 0; i < m; i++) {
      if (j >= w[i]) valid = 0;
    }
    if (((half == 1) && (valid == 1)) && (j > 0)) {
      cout << j;
      exit(0);
    }
  }
  cout << -1;
  return 0;
}
