#include <bits/stdc++.h>
using namespace std;
typedef struct Data {
  int id, val;
} tri;
typedef struct Data1 {
  int x, y;
} point;
void update(int BIT[], int n, int idx, int val) {
  if (idx == 0) {
    BIT[0] = 1;
    return;
  }
  while (idx <= n) {
    BIT[idx] += val;
    idx += (idx & -idx);
  }
  return;
}
int query(int BIT[], int n, int idx) {
  int ans = 0;
  while (idx > 0) {
    ans += BIT[idx];
    idx -= (idx & -idx);
  }
  return ans + BIT[0];
}
bool compare(tri a, tri b) {
  if (a.val < b.val) return true;
  if (a.val > b.val) return false;
  if (a.id < b.id) return true;
  return false;
}
long long solve(tri A[], int BIT[], int n, int val) {
  int j = 0, ans = 0;
  for (int i = 0; i <= n; i++) {
    while (A[j].val + val <= A[i].val && j <= n) {
      update(BIT, n, A[j].id + 1, 1);
      j++;
    }
    ans += query(BIT, n, A[i].id);
  }
  return (long long)ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, i, x, max = 0, min = 9999999, min1 = 9999999;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    max = std::max(max, x);
    min = std::min(min, x);
  }
  for (int i = 1; i <= m; i++) {
    cin >> x;
    min1 = std::min(min1, x);
  }
  int t1 = min * 2, t2 = max, t3 = min1;
  t1 = std::max(t1, t2);
  if (t1 >= t3)
    puts("-1");
  else
    cout << t1 << endl;
  return 0;
}
