#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N,p,q;
  cin>>N;
  vector<pair<int,int>> A;
  REP(i,N){
    int a;
    cin>>a;
    A.push_back(make_pair(a,i));
  }
  SORT(A);
  bool CAN=false;
  if(A[N-1].first==A[N-2].first) CAN=true;
  else{
    p=A[N-1].second;
    q=A[N-2].first;
  }
  
  if(CAN){
    REP(i,N) cout<<A[N-1].first<<endl;
  }
  else{
    if(i==p) cout<<q<<endl;
    else cout<<A[N-1].first<<endl;
  }
}