#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<pii> A(N);
  for (int i = 0; i < N; i++) cin >> A[i].first, A[i].second = i;
  sort(A.begin(), A.end());
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    if (A[i].second == N - 1)
      ans[i] = A[N - 2].first;
    else
      ans[i] = A[N - 1].first;
  }
  for (auto it : ans) cout << it << endl;
  return 0;
}
