#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int a[200010] = {0};
  int x, max = 0, sec = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> a[i];
  for (int i = 1; i <= N; i++) {
    if (a[i] > max) {
      sec = max;
      max = a[i];
      x = i;
    } else if (a[i] < max && a[i] > sec)
      sec = a[i];
  }
  for (int i = 1; i <= N; i++) {
    if (i != x)
      cout << max << endl;
    else
      cout << sec << endl;
  }
  return 0;
}
