#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, ans1 = 0, ans2 = 0;
  cin >> n;
  long long a[n + 2];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= n; i++) {
    ans1 = max(ans1, a[i]);
    if (a[i] != ans1) ans2 = max(ans2, a[i]);
  }
  for (i = 1; i <= n; i++) {
    if (a[i] != ans1)
      cout << ans1 << endl;
    else
      cout << ans2 << endl;
  }
  return 0;
}
