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