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