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