#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int max = 0;
  int max2 = 0;
  int key = 0;
  bool flag = false;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (max == A[i]) {
      flag = true;
    } else if (A[i] > max) {
      max = A[i];
      flag = false;
      key = i;
    } else if (max2 < A[i]) {
      max2 = A[i];
    }
  }
  for (int i = 0; i < N; i++) {
    if (flag == false && i == key) {
      cout << max2 << endl;
      continue;
    }
    cout << A[key] << endl;
  }
  return 0;
}
