#include <bits/stdc++.h>
using namespace std;
int main() {
  int N = 0;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int max1 = 0;
  int max2 = 0;
  for (int i = 0; i < N; i++) {
    if (max1 < A[i]) {
      max1 = A[i];
    } else if (max2 < A[i]) {
      max2 = A[i];
    }
  }
  cout << max1 << "\n";
  if (max1 < A[0]) {
    max1 = A[0];
  } else if (max2 < A[0]) {
    max2 = A[0];
  }
  for (int i = 1; i < N; i++) {
    int result = 0;
    if (A[i] == max1) {
      cout << max2 << "\n";
    } else {
      cout << max1 << "\n";
    }
  }
  return 0;
}
