#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n;
  cin >> n;
  vector<long long> A(n);
  long long first, second;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    if (second <= A[i]) {
      if (first <= A[i]) {
        second = first;
        first = A[i];
      } else {
        second = A[i];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (A[i] == first) {
      cout << second << endl;
    } else {
      cout << first << endl;
    }
  }
  return 0;
}
