#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  long long max = 0;
  long long submax = 0;
  int maxind;
  if (A[1] <= A[2]) {
    max = A[2];
    submax = A[1];
    maxind = 2;
  } else {
    max = A[1];
    submax = A[2];
    maxind = 1;
  }
  for (int i = 2; i < N; i++) {
    if (A[i] > max) {
      submax = max;
      max = A[i];
      maxind = i;
    } else if (A[i] > submax) {
      submax = A[i];
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i] == max)
      cout << submax << endl;
    else
      cout << max << endl;
  }
}
