#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int INF = 2e9;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<int> podaroci(n);
for(int i = 0; i < n; i++) {
cin >> podaroci[i];
}
int m;
cin >> m;
vector<int> kutii(m);
for(int i = 0; i < m; i++) {
cin >> kutii[i];
}
sort(podaroci.begin(), podaroci.end());
sort(kutii.begin(), kutii.end());
int najmala_razlika = INF;
int podarok = -1;
for(int i = 0; i < n; i++) {
int idx = lower_bound(kutii.begin(), kutii.end(), podaroci[i]) - kutii.begin();
if(idx >= 0 and idx < m) {
int razlika = kutii[idx] - podaroci[i];
if(najmala_razlika >= razlika) {
najmala_razlika = razlika;
if(podaroci[i] > podarok) {
podarok = podaroci[i];
}
}
}
}
cout << podarok << endl;
return 0;
}