#include <bits/stdc++.h>
using namespace std;
const int N = 20000;
int main() {
  int n, array[N], max_value1 = -1, max_value2 = -1, max_index;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> array[i];
  }
  for (int i = 0; i < n; i++) {
    if (max_value1 < array[i]) {
      max_value1 = array[i];
      max_index = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == max_index) continue;
    if (max_value2 < array[i]) {
      max_value2 = array[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (i != max_index)
      cout << max_value1 << endl;
    else
      cout << max_value2 << endl;
  }
}
