#include <bits/stdc++.h>
using namespace std;
void swap(int *u, int *v) {
  int temp = *u;
  *u = *v;
  *v = *u;
}
int main(void) {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int m[2] = {0};
  for (int i = 0; i < n; i++) {
    if (a[i] > m[1]) {
      m[1] = a[i];
    }
    if (m[0] < m[1]) {
      swap(&m[0], &m[1]);
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != m[0]) {
      cout << m[0] << endl;
    } else {
      cout << m[1] << endl;
    }
  }
  return 0;
}
