#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 200000;
int m1, m2, d[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    if (d[i] > m1)
      m1 = d[i];
    else if (d[i] > m2)
      m2 = d[i];
  }
  for (int i = 1; i <= n; i++) {
    if (d[i] == m1)
      printf("%d\n", m2);
    else
      printf("%d\n", m1);
  }
  return 0;
}
