#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t n, cnt = 0, ans = 0, lose = 0;
  cin >> n;
  vector<int64_t> x(n), y;
  for (int64_t i = 0; i < (n); i++) {
    cin >> x[i];
    y.push_back(x[i]);
    if (x[i] >= cnt) {
      cnt = x[i];
      ans = i;
    }
  }
  sort((y).begin(), (y).end());
  for (int64_t i = 0; i < (n); i++) {
    if (i == ans) {
      cout << y[1] << '\n';
    } else {
      cout << cnt << '\n';
    }
  }
}
