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