#include <bits/stdc++.h>
using namespace std;
const long mod = 1e9 + 7;
const int size = 1e5;
int main() {
  int N;
  cin >> N;
  int A[N];
  int a = 0, b = 0, temp = -1;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (a < A[i]) {
      b = a;
      a = A[i];
      temp = i;
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == temp)
      cout << b << endl;
    else
      cout << a << endl;
  }
}
