#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  vector<int> v(N);
  vector<int> so(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  v = vec;
  so = vec;
  sort(so.begin(), so.end());
  for (int i = 0; i < N; i++) {
    if (v.at(i) == so.at(N - 1)) {
      v.erase(v.begin() + i);
      sort(v.begin(), v.end());
      cout << v.at(N - 2) << endl;
      v = vec;
    } else
      cout << so.at(N - 1) << endl;
  }
}
