#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, a[2 * 10 ^ 5], maxnum, max, maxs, i;
  cin >> n;
  for (i = 0; i < (n); i++) {
    cin >> a[i];
  }
  max = a[0];
  maxnum = 0;
  for (i = 0; i < (n); i++) {
    if (max < a[i]) {
      max = a[i];
      maxnum = i;
      a[i] = 0;
    }
  }
  maxs = a[0];
  for (i = 0; i < (n); i++) {
    if (maxs < a[i]) {
      maxs = a[i];
      a[i] = 0;
    }
  }
  for (i = 0; i < (n); i++) {
    if (maxnum == i) {
      cout << maxs << endl;
    } else {
      cout << max << endl;
    }
  }
  return 0;
}
