#include <bits/stdc++.h>
int main() {
  int n;
  int a[100000];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int no1;
  int no2;
  for (int i = 0; i < n; i++) {
    if (a[i] > no1) {
      no2 = no1;
      no1 = a[i];
    } else if (a[i] > no2) {
      no2 = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != no1) {
      printf("%d\n", no1);
    } else {
      printf("%d\n", no2);
    }
  }
  return 0;
}
