#include <bits/stdc++.h>
using namespace std;

vector<int> b;
multiset<int,greater<int>> a;

int main() {
	
	int n,val;
	cin>>n;
	
	for(int i =0; i<n;i++){
		cin>>val;
		a.insert(val);
		b.push_back(val);
	}
	
	for(int i = 0;i<n;i++){
		a.erase(a.find(b[i]));
		cout<<*a.begin()<<endl;
		a.insert(b[i]);
	}
	
	
	
	return 0;
}