#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 A_max = 0;
  for (int i = 0; i < (N); ++i) A_max = max(A_max, A[i]);
  int A2 = 0;
  for (int i = 0; i < (N); ++i) {
    if (A[i] == A_max) continue;
    A2 = max(A2, A[i]);
  }
  for (int i = 0; i < (N); ++i) {
    if (A[i] == A_max) {
      cout << A2 << endl;
      i++;
    }
    cout << A_max << endl;
  }
  return 0;
}
