#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  long long maximum = 0;
  long long maximum2 = 0;
  for (int i = 0; i < N; i++) {
    long long mark = maximum;
    maximum = max(maximum, A.at(i));
    if (maximum != mark) {
      maximum2 = mark;
    }
  }
  for (int i = 0; i < N; i++) {
    if (maximum == A.at(i)) {
      cout << maximum2 << endl;
    } else {
      cout << maximum << endl;
    }
  }
}
