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