#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], max = 0, max_2 = 0, max_num, max_num_2;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] > max) {
      max_num = i;
      max = a[i];
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i != max_num && a[i] > max_2) {
      max_num_2 = i;
      max_2 = a[i];
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i != max_num_2)
      cout << max << endl;
    else
      cout << max_2 << endl;
  }
  return 0;
}
