#include <bits/stdc++.h>
using namespace std;
int main() {
  priority_queue<int> Q;
  int A[200001];
  int N, first, second;
  cin >> N;
  for (int i = 0; i <= N; i++) cin >> A[i], Q.push(A[i]);
  first = Q.top(), Q.pop(), second = Q.top();
  for (int i = 0; i <= N; i++) {
    if (A[i] == first)
      cout << second << endl;
    else
      cout << first << endl;
  }
  return 0;
}
