#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N), temp_A(N);
  for (int i = 0; i < N; i++) {
    int v;
    cin >> v;
    A[i] = v;
    temp_A[i] = v;
  }
  sort(temp_A.begin(), temp_A.end());
  int largest = temp_A[temp_A.size() - 1];
  int second_largest = temp_A[temp_A.size() - 1];
  if (temp_A.size() > 1) {
    second_largest = temp_A[temp_A.size() - 2];
  }
  vector<int> index_largest;
  for (int i = 0; i < N; i++) {
    if (A[i] == largest) {
      index_largest.push_back(i);
    }
  }
  for (int i = 0; i < N; i++) {
    bool is_largest = find(index_largest.begin(), index_largest.end(), i) !=
                      index_largest.end();
    if (is_largest) {
      cout << second_largest << endl;
    } else {
      cout << largest << endl;
    }
  }
}
