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