#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  vector<pair<int, int> > ar(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ar[i] = {x, i};
  }
  sort(ar.begin(), ar.end());
  reverse(ar.begin(), ar.end());
  int fidx = ar[0].second;
  for (int i = 0; i < n; i++) {
    if (i == fidx)
      cout << ar[1].first << "\n";
    else
      cout << ar[0].first << "\n";
  }
  return 0;
}
