#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 largest = A[0];
  int next_largest = largest;
  for (int i = 0; i < N; i++) {
    if (A[i] >= largest) {
      next_largest = largest;
      largest = A[i];
    } else if (A[i] > next_largest) {
      next_largest = A[i];
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i] == largest) {
      cout << next_largest << endl;
    } else {
      cout << largest << endl;
    }
  }
  return 0;
}
