#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  std::cin >> n;
  int max = 0;
  int next = 0;
  int maxi = 0;
  int nexti = 0;
  for (int i = 0; i < n; i++) {
    int now = 0;
    std::cin >> now;
    if (now >= max) {
      next = max;
      nexti = maxi;
      max = now;
      maxi = i;
    } else if (now >= next) {
      next = now;
      nexti = maxi;
    }
  }
  for (int i = 0; i < n; i++) {
    int result = i == nexti ? next : max;
    std::cout << result << std::endl;
  }
}
