#include <bits/stdc++.h>
int a[1000010];
int main() {
  int n, x, y, cnt;
  while (~scanf("%d", &n)) {
    cnt = 0;
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    x = y = a[0];
    for (int i = 1; i < n; i++) {
      if (a[i] > x) {
        y = x;
        x = a[i];
      } else if (a[i] < x && a[i] > y)
        y = a[i];
    }
    for (int i = 0; i < n; i++)
      if (a[i] == x) cnt++;
    for (int i = 0; i < n; i++) {
      if (a[i] == x && cnt == 1)
        printf("%d\n", y);
      else
        printf("%d\n", x);
    }
  }
  return 0;
}
