#include <bits/stdc++.h>
using namespace std;
int N;
int A[200001];
int main() {
  int N;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  int max = A[1];
  int max_i = 1;
  int max2 = INT_MAX;
  int max2_i;
  for (int i = 2; i <= N; i++) {
    if (A[i] >= max) {
      max2_i = max_i;
      max2 = max;
      max_i = i;
      max = A[i];
    } else if (A[i] >= max2) {
      max2 = A[i];
      max2_i = i;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (i == max_i)
      cout << max2 << endl;
    else
      cout << max << endl;
  }
}
