#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) cin >> a[i];
  int ind = max_element(a, a + N) - a;
  int mx = *max_element(a, a + N);
  for (int i = 0; i < N; i++) {
    if (i == ind) {
      cout << max(*max_element(a, a + ind), *max_element(a + ind + 1, a + N))
           << endl;
    } else {
      cout << mx << endl;
    }
  }
  return 0;
}
