#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int V[N];
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }
  int max_1 = V[0], max_2 = V[0];
  for (int i = 0; i < N; i++) {
    if (V[i] > max_1) max_1 = V[i];
    if (V[i] < max_1 && V[i] > max_2) max_2 = V[i];
    if (N > 2 && i == N - 1 && max_1 == V[N - 1]) {
      max_2 = V[N - 2];
    }
  }
  if (max_2 == 0) {
    for (int i = 0; i < N; i++) {
      cout << max_1 << endl;
    }
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (V[i] == max_1)
      cout << max_2 << endl;
    else
      cout << max_1 << endl;
  }
  return 0;
}
