#include <bits/stdc++.h>
using namespace std;
int static fast = []() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  return 0;
}();
int main() {
  int n;
  cin >> n;
  vector<int> arr(n, 0);
  for (int i = 0; i < n; i++) cin >> arr[i];
  auto it = max_element(arr.begin(), arr.end());
  int idx = distance(arr.begin(), it);
  int M = *it;
  for (int i = idx; i < n - 1; i++) {
    arr[i] = arr[idx + 1];
  }
  int M2 = *max_element(arr.begin(), arr.end() - 1);
  for (int i = 0; i < n; i++) {
    if (i == idx)
      cout << M2 << endl;
    else
      cout << M << endl;
  }
}
