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