#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
int main() {
  int N;
  cin >> N;
  vector<Pi> Ai(N);
  for (int i = (int)(0); i < (int)(N); i++) {
    cin >> Ai[i].first;
    Ai[i].second = i;
  }
  sort(Ai.begin(), Ai.end(), greater<Pi>());
  int a = Ai[0].second;
  int b = Ai[1].second;
  for (int i = (int)(0); i < (int)(N); i++) {
    if (i != a)
      cout << Ai[0].first << endl;
    else
      cout << Ai[0].first << endl;
  }
}
