#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  ll n;
  cin>>n;
  vector<ll> a[n];
  vector<ll> b[n];
  rep(i,n){
    cin>>a[i];
    b[i]=a[i];
  }
  sort(b.begin(),b.end());
  ll max1=b[n-1];
  ll max2=b[n-2];
  rep(i,n){
    if(a[i]==max1){
      cout<<max2<<endl;
    }else{
      cout<<max1<<endl;
    }
  }
}