#include <bits/stdc++.h>
using namespace std;
long long n, arr[200005], bsr1, idxbsr, bsr2;
long long t, a, b, c;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= n; i++) {
    if (arr[i] >= bsr1) {
      bsr1 = arr[i];
      idxbsr = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (arr[i] >= bsr2 && i != idxbsr) {
      bsr2 = arr[i];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i == idxbsr)
      cout << bsr2 << endl;
    else
      cout << bsr1 << endl;
  }
}
