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