#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

int main() {
 int n; cin >> n;
 int a[n],b[n];
 rep(i,n) cin >> a[i];
 memcpy(b,a,sizeof(a));
 sort(b,b+n);
 int max = b[n-1]; int max2 = b[n-2];
 rep(i,n) (a[i]==max)?cout<<max2<<endl:cout<<max<<endl;
}