#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, ret, maxval, mval, mval2;
  cin >> N;
  vector<int> A(N);
  mval = 0;
  mval2 = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (mval < A.at(i)) mval = A.at(i);
  }
  for (int i = 0; i < N; i++) {
    if ((mval != A.at(i)) && (mval2 < A.at(i))) mval2 = A.at(i);
  }
  for (int i = 0; i < N; i++) {
    maxval = mval;
    if (mval == A.at(i)) {
      maxval = mval2;
    }
    cout << maxval << endl;
  }
}
