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