#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, max = 1, maxNum = 0;
  cin >> N;
  vector<int> a(N), b(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    b.at(i) = a.at(i);
    if (a.at(i) > max) {
      max = a.at(i);
      maxNum = i;
    }
  }
  sort(b.begin(), b.end());
  reverse(b.end(), b.begin());
  for (int i = 0; i < N; i++) {
    if (i == maxNum) {
      cout << b.at(1) << endl;
      ;
    } else {
      cout << max << endl;
    }
  }
}
