#include <bits/stdc++.h>
using namespace std;
int maxv;
int main() {
  int n;
  cin >> n;
  int a[n], b[n];
  int i;
  for (i = 0; i < n; ++i) {
    cin >> a[i];
    b[i] = a[i];
    if (a[i] > a[maxv]) maxv = i;
  }
  sort(b, b + n);
  for (i = 0; i < n; ++i) {
    if (i == maxv)
      cout << b[1] << endl;
    else
      cout << a[maxv] << endl;
  }
  return 0;
}
