#include <bits/stdc++.h>
using namespace std;

int main() {
	 int n ; 
    cin>>n ; 
    vector <int> b ; 
    int i = 0 ; 
    while(i<n){
        int x ; cin>>x ; 
        b.push_back(x);
        i++;
    }
    sort(b.begin(), b.end());
    int t;cin>>t;
    int l=0, r=b.size();
    while(l<r){
    	int m=(l+r)/2;
    	if(b[m]<=t) l=m+1;
    	else{
    		r=m;
    	}
    }
    cout<<b[l];// return element just greater than target
	return 0;
}