#include <bits/stdc++.h>
int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  int max = 0;
  int semi = 0;
  int max_i = 0;
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
    if (max <= A[i]) {
      max = A[i];
      max_i = i;
    }
    if (semi < A[i] && A[i] <= max && max_i != i) semi = A[i];
  }
  if (max_i == N - 1) {
    for (int i = 0; i < N; ++i) std::cout << max << std::endl;
  } else {
    for (int i = 0; i < N; ++i) {
      if (i == max_i)
        std::cout << semi << std::endl;
      else
        std::cout << max << std::endl;
    }
  }
  return 0;
}
