#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int MAX = 0, MAXi;
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    if (a.at(i) > MAX) {
      MAX = a.at(i);
      MAXi = i;
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == MAXi) {
      int MAX2 = 0;
      for (int j = 0; i < N; j++) {
        if (j != i) MAX2 = max(MAX2, a.at(j));
      }
      cout << MAX2 << endl;
    } else {
      cout << MAX << endl;
    }
  }
}
