#include <bits/stdc++.h>
using namespace std;
using lint = long long;
int main() {
  int N;
  cin >> N;
  int array[N];
  for (int i = 0; i < N; i++) {
    cin >> array[i];
  }
  int max = 0;
  int number = 0;
  int max2 = 0;
  for (int i = 0; i < N; i++) {
    if (max < array[i]) {
      max2 = max;
      max = array[i];
      number = i;
    } else
      max = max;
  }
  for (int i = 0; i < N; i++) {
    if (i == number)
      cout << max2 << endl;
    else
      cout << max << endl;
  }
}
