#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
const int INF = 1e9;
const long long MOD = 1e9 + 7;
int N, A[MAX];
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  int maxi[2];
  maxi[0] = maxi[1] = 0;
  for (int i = 0; i < N; i++) {
    if (maxi[0] < A[i]) {
      maxi[1] = maxi[0];
      maxi[0] = A[i];
    } else if (maxi[1] < A[i]) {
      maxi[1] = A[i];
    }
  }
  for (int i = 0; i < N; i++) {
    if (maxi[0] == A[i])
      cout << maxi[1] << endl;
    else
      cout << maxi[0] << endl;
  }
}
