#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a, t, s;
  int ans = 0;
  int max, max2;
  std::vector<int> A;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    if (ans < a) {
      s = i;
    }
    A.push_back(a);
  }
  max = *max_element(A.begin(), A.end());
  t = A[s];
  A.erase(A.begin() + s);
  max2 = *max_element(A.begin(), A.end());
  A.insert(A.begin() + s, t);
  for (int i = 0; i < N; i++) {
    if (A[i] != max) {
      cout << max << endl;
    } else {
      cout << max2 << endl;
    }
  }
  return 0;
}
