#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  int arr[a], max1 = 0, max2 = 0;
  for (int i = 0; i < a; i++) {
    cin >> arr[i];
    if (arr[i] > arr[max1])
      max1 = i;
    else if (arr[i] > arr[max2])
      max2 = i;
  }
  for (int i = 0; i < a; i++) {
    if (i == max1)
      printf("%d\n", arr[max2]);
    else
      printf("%d\n", arr[max1]);
  }
  return 0;
}
