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