#include <bits/stdc++.h>
int main(void) {
  int n, a, max1 = 0, max2 = 0, count = 0;
  std::vector<int> position_max1;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    if (a > max1) {
      max2 = max1;
      max1 = a;
      position_max1 = {i};
    } else if (a == max1) {
      position_max1.push_back(i);
    } else if (max1 > a && a > max2) {
      max2 = a;
    }
  }
  if (0 == max2) {
    max2 = max1;
  }
  for (int i = 0; i < n; i++) {
    if (i == position_max1[count]) {
      printf("%d\n", max2);
      count++;
    } else {
      printf("%d\n", max1);
    }
  }
}
