#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> v(N, 0);
  int max = 0, nmax = 0;
  for (int i = 0; i < N; i++) {
    cin >> v[i];
    if (v[i] > max) max = v[i];
  }
  for (int i = 0; i < N; i++) {
    if (v[i] > nmax && v[i] != max) nmax = v[i];
  }
  for (int i = 0; i < N; i++) {
    if (v[i] == max)
      cout << nmax << "\n";
    else
      cout << max << "\n";
  }
}
