#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  int s[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    s[i] = A[i];
  }
  int max = 0;
  for (int i = 0; i < N; i++) {
    if (max < A[i]) {
      max = A[i];
    }
  }
  sort(s, s + N);
  for (int i = 0; i < N; i++) {
    if (A[i] == max) {
      cout << s[1] << endl;
    } else {
      cout << max << endl;
    }
  }
  return 0;
}
