#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  vector<int> A(n,0);
  rep(i,n) cin>>A.at(i);
  int max=0;
  rep(i,n) max=max(max,A.at(i));
  int submax=0;
  rep(i,n)(A.at(i)==max)?continue :submax=max(submax,A.at(i));
  rep(i,n)(A.at(i)==max)?cout<<max<<endl:cout<<submax<<endl;
}
