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