#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int maxx = 0;
  int sub = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (maxx <= a[i]) {
      maxx = a[i];
      sub = maxx;
    } else if (sub < a[i]) {
      sub = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == maxx)
      cout << sub << endl;
    else
      cout << maxx << endl;
  }
}
