#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
  cin>>n;
  int a[n];
  priority_queue<int>q;
  for(int i=0;i<n;i++)
  {cin>>a[i];
   q.push(a[i]);
  }
for(int i=0;i<n;i++)
{
 if(a[i]==q.top())
 {
 q.pop();
   cout<<q.top()<<endl;
   q.push(a[i]);
 }
  else
    cout<<q.top()<<endl;
}
}