//sumitraj387
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define string str
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
main()
{
   int n,i,indx;
   cin>>n;
   vector<int>v(n),v1;
   for(i=0;i<n;i++)
   cin>>v[i];
   v1=v;
   int max1=*max_element(v.begin(),v.end());
   sort(v1.begin(),v1.end());
   for(i=0;i<n;i++)
   {
       if(v1[i]==max1)
       {
           indx=i;
           break;
       }
   }
   v1.erase(v1.begin()+i,v1.end());
   int max2=v1.back();
   for(i=0;i<n;i++)
   {
       if(v[i]!=max1)
       {
           cout<<max1<<endl;
       }
        else
        {
           if(v1.size()==0)
           cout<<max1<<endl;
           else
           cout<<max2<<endl;
        }
    }
}
