#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int higher[2] = {0, 0};
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    if (higher[0] < A[i]) {
      higher[1] = higher[0];
      higher[0] = A[i];
    }
  }
  for (int i = 0; i < N; ++i) {
    if (higher[0] != A[i])
      cout << higher[0] << endl;
    else
      cout << higher[1] << endl;
  }
}
