#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < (int)(N); i++) cin >> A[i];
  int a = A[0], aa = A[0];
  for (int i = 0; i < (int)(N); i++) {
    if (A[i] >= a) {
      aa = a;
      a = A[i];
    } else if (A[i] >= aa) {
      aa = A[i];
    }
  }
  for (int i = 0; i < (int)(N); i++) {
    if (A[i] == a)
      cout << aa << endl;
    else
      cout << a << endl;
  }
}
