#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int A[N];
  int y = 0;
  int yi = 0;
  int y2 = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (y <= A[i]) {
      y2 = y;
      y = A[i];
      yi = i;
    } else if (y2 < A[i]) {
      y2 = A[i];
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == yi) {
      std::cout << y2 << '\n';
    } else {
      std::cout << y << '\n';
    }
  }
  return 0;
}
