#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int vm[n];
  vm[0] = a[0];
  int frag = 0;
  int sv;
  for (int i = 1; i < n; i++) {
    if (a[i] > vm[i - 1]) {
      sv = vm[i - 1];
      vm[i] = a[i];
      frag = 0;
    } else {
      if (sv < a[i] && a[i] < vm[i - 1]) sv = a[i];
      vm[i] = vm[i - 1];
      if (a[i] == vm[i - 1]) frag = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (vm[n - 1] != a[i])
      cout << vm[n - 1] << endl;
    else if (frag == 0)
      cout << sv << endl;
    else
      cout << vm[n - 1] << endl;
  }
  return 0;
}
