#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < (N); i++) {
    cin >> A[i];
    B[i] = A[i];
  }
  sort(B.begin(), B.end(), greater<int>());
  int max_a = B[0];
  int max_b = B[0];
  for (int i = 0; i < (N); i++) {
    if (B[i] != max_a) {
      max_b = B[i];
      break;
    }
  }
  for (int i = 0; i < (N); i++) {
    if (A[i] == max_a)
      cout << max_b << endl;
    else
      cout << max_a << endl;
  }
}
