#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a, m = 0, nm = 0, mi;
  cin >> N;
  cin >> m >> nm;
  if (nm > m) swap(nm, m);
  for (int i = 2; i < N; i++) {
    cin >> a;
    if (a > m) {
      nm = m;
      m = a;
      mi = i;
    } else if (a > nm) {
      nm = a;
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == mi) cout << nm << endl;
    if (i != mi) cout << m << endl;
  }
}
