#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18 + 1;
bool compare_by_pair(pair<long, long> a, pair<long, long> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  }
  return a.second == b.second;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long idx = 0;
  long N;
  cin >> N;
  vector<pair<long, long>> A(N);
  long a;
  for (size_t i = 0; i < N; i++) {
    cin >> a;
    A[i] = make_pair(i, a);
  }
  sort(A.rbegin(), A.rend(), compare_by_pair);
  for (size_t i = 0; i < N; i++) {
    if (i == A[0].first)
      cout << A[1].second << endl;
    else
      cout << A[0].second << endl;
  }
  return 0;
}
