#include <bits/stdc++.h>
using namespace std;
ifstream f("2.in");
int main() {
  long long N;
  f >> N;
  long long A[N];
  for (int i = 0; i < N; i++) f >> A[i];
  int max1 = 0, max2 = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] > A[max1]) max1 = i;
  }
  for (int i = 0; i < N; i++) {
    if (A[i] == A[max1])
      continue;
    else if (A[i] > A[max2])
      max2 = i;
  }
  for (int i = 0; i < N; i++) {
    if (A[i] == A[max1])
      cout << A[max2] << '\n';
    else
      cout << A[max1] << '\n';
  }
  return 0;
}
