#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, maxim1 = 0, maxim2 = 0;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (maxim1 < a[i]) {
      maxim2 = maxim1;
      maxim1 = a[i];
    }
  }
  maxim2 = max(maxim2, a[n - 1]);
  for (int i = 0; i < n; i++) {
    if (maxim1 == a[i])
      printf("%d\n", maxim2);
    else
      printf("%d\n", maxim1);
  }
}
