#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<int> A(N), a(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    a[i] = A[i];
  }
  sort((a).begin(), (a).end(), 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;
    }
  }
}
