#include <bits/stdc++.h>
using namespace std;
int main(void) {
  unsigned long a[(200000)];
  unsigned long n;
  unsigned long amax1, amax2;
  cin >> n;
  for (int loop = 0; loop < n; loop++) {
    cin >> a[loop];
    if (amax1 <= a[loop]) {
      amax2 = amax1;
      amax1 = a[loop];
    }
  }
  for (int loop = 0; loop < n; loop++) {
    if (a[loop] != amax1)
      cout << amax1 << endl;
    else
      cout << amax2 << endl;
  }
  return 0;
}
