#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  int ma1 = 0, ma2 = 0, p1 = -1, a;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (a > ma1) {
      ma2 = ma1;
      ma1 = a;
      p1 = i;
    } else if (a > ma2) {
      ma2 = a;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i == 1) {
      cout << ma2 << endl;
    } else {
      cout << ma1 << endl;
    }
  }
  return 0;
}
