#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<pair<int, int> > A(N);
  for (int i = 0; i < N; i++) {
    int t;
    cin >> t;
    A.at(i) = make_pair(t, i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  for (int i = 0; i < N; i++) {
    if (i != A.at(0).second)
      cout << A.at(0).first << endl;
    else
      cout << A.at(1).first << endl;
  }
}
