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