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