#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int ara[n];
  for (int i = 0; i < n; i++) cin >> ara[i];
  int mx1, mx2, x, y;
  if (ara[0] > ara[1])
    mx1 = ara[0], mx2 = ara[1], x = 0, y = 1;
  else
    mx1 = ara[1], mx2 = ara[0], x = 1, y = 0;
  for (int i = 2; i < n; i++) {
    if (ara[i] > mx1) {
      mx2 = mx1;
      mx1 = ara[i];
      y = x;
      x = i;
    } else if (ara[i] > mx2 && ara[i] != mx1) {
      mx2 = ara[i];
      y = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == x)
      cout << mx2;
    else
      cout << mx1;
    cout << " ";
  }
  return 0;
}
