#include <bits/stdc++.h>
using namespace std;
int N;
int A[20000];
int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> A[i];
  int max = 0;
  int i_max = 0;
  int max2 = 0;
  int i_max2 = 0;
  for (int i = 0; i < N; ++i) {
    if (max < A[i]) {
      max = A[i];
      i_max = i;
    } else if (max >= A[i] && A[i] > max2) {
      max2 = A[i];
      i_max2 = i;
    }
  }
  for (int j = 0; j < N; ++j) {
    if (j != i_max) {
      cout << max << endl;
    } else {
      cout << max2 << endl;
    }
  }
}
