#include <iostream> #include <algorithm> using namespace std; int main(){ int n,m; cin >> n >> m; int minCorrectTime =1000, maxCorrectTime = 0, minWrongTime = 1000,tmp; for(int i = 0 ; i < n; i ++){ cin >> tmp; minCorrectTime = min(tmp,minCorrectTime); maxCorrectTime = max(tmp,maxCorrectTime); } for(int i = 0 ; i < m ; ++ i ){ cin >> tmp; minWrongTime = min(minWrongTime,tmp); } if(maxCorrectTime < minWrongTime && 2*minCorrectTime < minWrongTime) cout<<max(maxCorrectTime,2*minCorrectTime)<<endl; else cout<<-1<<endl; return 0; }