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