#include <bits/stdc++.h>
using namespace std;

#define MAX_N 200000
int N;
int A;

int main()
{
  int max1, max2 = -1, -2;
  int idx1, idx2 =  0,  0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A;
    if (A > max1) {
      max2 = max1;
      idx2 = idx1;
      max1 = A;
      idx1 = i;
    } else if (A > max2) {
      max2 = A;
      idx2 = i;
    }
  }

  for (int i = 0; i < N; i++) {
    if (i == idx1) {
      cout << max2 << endl;
    } else {
      cout << max1 << endl;
    }
  }
  return 0;
}