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

int main() {
 int n,j;cin>>n; int a[n],s[n];for(int i=0 ;i<n;i++) {
   s[i]=0;cin>>a[i] ;
 }
  if(i!=0 && i!=n-1){
  for(int i=0;i<n;i++){
    
      for(j=0;j<i;j++) if(a[j]>s[i])s[i]=a[j];
      for(j=i+1;j<n;j++)if(a[j]>s[i])s[i]=a[j];
    }
    
  }
    
    else if(i==0){
      for(j=1;j<n;j++)if(a[j]>s[i])s[i]=a[j];
    }
    
    else if (i==n-1){
      for(j=0;j<n-1;j++)if(a[j]>s[i])s[i]=a[j];
    }
    cout<<s[i]<<endl;
  
  
}