#include <bits/stdc++.h>
using namespace std;
void solve(long long N, std::vector<long long> A) {
  vector<long long> tmp = A;
  auto it = max_element((A).begin(), (A).end());
  tmp.erase(it);
  auto secondit = max_element((tmp).begin(), (tmp).end());
  for (long long i = 0; i < (long long)(N); i++) {
    cout << ((i == distance(A.begin(), it)) ? *it : *secondit) << endl;
  }
}
int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}
