#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];
  pair<int, int> max1, max2;
  if (A[0] < A[1]) {
    max1 = make_pair(A[1], 1);
    max2 = make_pair(A[0], 0);
  } else {
    max1 = make_pair(A[0], 0);
    max2 = make_pair(A[1], 1);
  }
  for (int i = 2; i < N; i++) {
    if (max1.first <= A[i]) {
      max2 = max1;
      max1 = make_pair(A[i], i);
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == max1.second)
      cout << max2.first << endl;
    else
      cout << max1.first << endl;
  }
  return 0;
}
