#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, a[200000], max = 0, max1 = 0, i, j, t = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > max) {
      max = a[i];
      t = i;
    }
  }
  for (i = 0; i < n; i++) {
    if (i != t) {
      cout << max << endl;
    } else {
      for (j = 0; j < n; j++) {
        if (max1 < a[j] && max1 < max) {
          max1 = a[i];
        }
      }
      cout << max1 << endl;
    }
  }
  return 0;
}
