#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  double sum = 0;
  vector<int> v1(n);
  vector<int> v2(n);
  for (int i = 0; i < (n); ++i) {
    int a;
    cin >> v1.at(i);
  }
  v2 = v1;
  int max = *std::max_element(v1.begin(), v1.end());
  int max2;
  for (int i = 0; i < (n); ++i) {
    if (v1.at(i) == max) {
      v2.erase(v2.begin() + i);
      max2 = *std::max_element(v2.begin(), v2.end());
      printf("%d\n", max2);
    } else {
      printf("%d\n", max);
    }
    v2 = v1;
  }
  return 0;
}
