#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int m1 = 0, m2 = 0;
  bool dup = false;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] == m1) dup = true;
    m1 = max(m1, A[i]);
  }
  for (int i = 0; i < N; ++i) {
    if (A[i] != m1) m2 = max(m2, A[i]);
  }
  for (int i = 0; i < N; ++i) {
    if (A[i] == m1 && !dup)
      cout << m2 << endl;
    else
      cout << m1 << endl;
  }
  return 0;
}
