#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll Max = 0, max = 0, N, A;
  vector<int> t;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A;
    if (A > Max) {
      max = Max;
      Max = A;
    } else if (A > Max) {
      max = A;
      t.push_back(A);
    }
  }
  for (int i = 0; i < N; i++) {
    if (t.at(i) != Max) {
      cout << Max << endl;
    } else {
      cout << max << endl;
    }
  }
  return 0;
}
