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