#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int maxi = -INT_MAX, second_max = -INT_MAX, max_index;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > maxi) {
      second_max = maxi;
      maxi = a[i];
      max_index = i;
    }
    if (a[i] < maxi && i == n - 1 && a[i] > second_max) second_max = a[i];
  }
  for (int i = 0; i < n; i++)
    cout << ((i == max_index) ? second_max : maxi) << endl;
  return 0;
}
