#include
#include <bits/stdc++.h>
using namespace std;
int getMaxArea(int a[],int n){
int res=0;
int tp;
int curr;
stack s;
for(int i=0; i<n ; i++){
while(s.empty()==false && a[s.top()]>=a[i]){
tp=s.top();s.pop();
curr=a[tp](s.empty()?i:i-s.top()-1);
res= max(res,curr);
}s.push(i);
}
while(s.empty()==false){
tp=s.top();s.pop();
curr=a[tp](s.empty()?n:n-s.top()-1);
res= max(res,curr);
}
return res;
}
int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
cout<<getMaxArea(a,n);
return 0;
}