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