#include <bits/stdc++.h>
using namespace std;
int n, m;
int max1 = -2147483647;
int max2 = -2137384637;
int a[2000010];
int main() {
  int i, j, k;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] > max1) {
      max1 = a[i];
      continue;
    }
    if (a[i] > max2 && max1 != a[i]) {
      max2 = a[i];
      continue;
    }
  }
  for (i = 1; i <= n; ++i) {
    if (a[i] != max1)
      printf("%d\n", max1);
    else if (max2 = -2147483647)
      printf("%d\n", max1);
    else
      printf("%d\n", max2);
  }
  cout << endl;
  return 0;
}
