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

int n, a[200004], left[200004], right[200004];

int main() {
	cin>>n;
	for(int i = 1;i<=n;i++)	cin>>a[i];
	left[0] = 0;
	// left[i] : maximum of a[1], a[2], ..., a[i]
	for(int i = 1;i<=n;i++)	left[i] = max(left[i-1], a[i]);
	
	// right[i] : maximum of a[i], a[i+1], ..., a[n]
	right[n+1] = 0;
	for(int i = n; i>=1; i--)	right[i] = max(right[i+1], a[i]);
	
	for(int i = 1;i<=n;i++)
		cout<<max(left[i-1], right[i+1])
	return 0;
}