#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);
  for (int i = 0; i < (N); i++) cin >> A[i];
  int max_a = A[0];
  int max_b = A[0];
  for (int i = 0; i < (N); i++) {
    max_a = max(max_a, A[i]);
    if (max_a != A[i]) {
      max_b = max(max_b, A[i]);
    }
  }
  for (int i = 0; i < (N); i++) {
    if (A[i] == max_a)
      cout << max_b << endl;
    else
      cout << max_a << endl;
  }
}
