#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<int> A(N), a(N);
  REP(i, N) {
    cin >> A[i];
    a[i] = A[i];
  }

  sort(ALL(a), greater<int>());
  int max1 = a[0];
  int max2 = a[1];

  for (int i = 0; i < N; ++i) {
    if (A[i] == max1) {
      cout << max2 << endl;
    } else {
      cout << max1 << endl;
    }
  }
}