#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M = -1, flag = 0, num, M2 = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (x > M) {
      M2 = M;
      swap(x, M);
      num = i;
      flag = 0;
    } else if (x == M)
      flag = 1;
  }
  for (int i = 0; i < N; i++) {
    if (num) {
      if (flag) {
        cout << M << endl;
      } else
        cout << M2 << endl;
    } else {
      cout << M << endl;
    }
  }
}
