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