#include <bits/stdc++.h>
using namespace std;
    
int main(){
  int N; cin >> N;
  vector<int> a(N);
  priority_queue<int, vector<int>, greater<int>> pq;
  
   for(int i = 0; i < N; i++)
  pq.push(at(i));
     MAX = pq.top();
  pq.pop();
	second = pq.top();

 for(int i = 0; i < N; i++){
   if(a.at(i) == MAX)
   cout << MAX << endl;
   else if(a.at(i) != MAX)
     cout << second << endl;
   } 
 }