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