#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> A(n), B(n);
  int max1 = 0, max2 = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
    if (A[i] > max2) {
      max2 = max1;
      max1 = A[i];
    } else if (A[i] > max1) {
      max1 = A[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (A[i] == max1)
      printf("%d\n", max2);
    else
      printf("%d\n", max1);
  }
}
int main(void) {
  solve();
  return 0;
}
