#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, A[200001];
  cin >> N;
  int MAX_id = 0, MAX2_id = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (i != 0) {
      if (A[MAX_id] <= A[i]) {
        MAX2_id = MAX_id;
        MAX_id = i;
      } else if (A[MAX2_id] <= A[i]) {
        MAX2_id = i;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == MAX_id)
      cout << A[MAX2_id] << endl;
    else
      cout << A[MAX_id] << endl;
  }
}
