#include<iostream>
#include<fstream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
	ifstream fi("SOAM.INP");
	long int n;
	fi>>n;
	long int a[n];
	for(long int i=0;i<n;i++)
        fi>>a[i];
	fi.close();
	ofstream fo("SOAM.OUT");
	long int maxa=0;
	long int k;
	for(long int i=0;i<n;i++)
    {
        if(a[i]<0){maxa=a[i];k=i;break;}
    }
    if(maxa==0){fo<<0;}
    else{
    for(long int i=k;i<n;i++)
    {
        if(a[i]<0 && a[i]>maxa){maxa=a[i];}
    }
    fo<<maxa;}
}
