#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int a[200500];
  int max = 0, sMax = 0;
  int n, num;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num;
    if (num > max) {
      max = num;
    } else if (max > sMax) {
      sMax = num;
    }
    a[i] = num;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == max)
      cout << sMax << endl;
    else
      cout << max << endl;
  }
  return 0;
}
