#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int cor[n], wro[m];     for (int i = 0; i < n; i++) cin >> cor[i];     for (int i = 0; i < m; i++) cin >> wro[i];     int tl;     sort(cor, cor + n);     sort(wro, wro + m);     int v = max(2 * cor[0], cor[n - 1]);     if (v < wro[0])       cout << v;     else       cout <<  -1 ;     return 0;   }   