#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, mx, mx2, temp;
  cin >> n;
  int a[n + 1], b[n + 1];
  mx = mx2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > mx) mx = a[i];
    if (a[i] > mx2 && a[i] != mx) mx2 = a[i];
  }
  for (int i = 0; i < n; i++) {
    (a[i] == mx) ? cout << mx2 << endl : cout << mx << endl;
  }
  return 0;
}
