#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int k = -1;
  int g = -2;
  int p;
  int q;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (k < a[i]) {
      g = k;
      k = a[i];
      p = i;
    }
    if (a[i] <= k && a[i] > g) {
      g = a[i];
    }
  }
  for (int j = 1; j <= n; j++) {
    if (j != p + 1) {
      cout << k << endl;
    } else {
      cout << g << endl;
    }
  }
}
