#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  std::priority_queue<long long> que;
  long long max, max2;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    que.push(A[i]);
  }
  max = que.top();
  que.pop();
  max2 = max;
  while (max2 == max && !que.empty()) {
    max2 = que.top();
    que.pop();
  }
  for (long long i = 0; i < N; i++) {
    if (A[i] == max) {
      cout << max2 << endl;
    } else {
      cout << max << endl;
    }
  }
}
