#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> A(N);
  int a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    A[i] = make_pair(a, i);
  }
  sort(A.begin(), A.end(), greater<pair<int, int>>());
  int maxIndex = A[0].second;
  int maxA = A[0].first;
  int secondA = A[1].first;
  for (int i = 0; i < N; i++) {
    if (i == maxIndex) {
      cout << maxA << endl;
    } else {
      cout << secondA << endl;
    }
  }
  return 0;
}
