#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int max = 1, smax = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] >= max) {
      smax = max;
      max = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == max) {
      printf("%d\n", smax);
    } else {
      printf("%d\n", max);
    }
  }
}
