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