#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<pair<int, int> > v(N);
  for (int i = 0; i < N; ++i) {
    cin >> v[i].first;
    v[i].second = i;
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < N; ++i) {
    if (v[N - 1].second != i)
      cout << v[N - 1].first << '\n';
    else
      cout << v[N - 2].first << '\n';
  }
  return 0;
}
