#include <bits/stdc++.h>
#pragma GCC optimize "03"
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int mx = -1, smx = -1;
  for (int i = 1; i <= n; i++) {
    int p;
    cin >> p;
    if (p >= mx) {
      smx = mx;
      mx = p;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i == mx)
      cout << smx << '\n';
    else
      cout << mx << '\n';
  }
  return 0;
}
