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