#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, t;
  cin >> N;
  vector<int> A(N);
  for (int& i : A) cin >> i;
  vector<int> B(A);
  sort(B.begin(), B.end(), greater<int>());
  B.erase(unique(B.begin(), B.end()), B.end());
  for (int i : A) cout << (i == B[0] ? B[1] : B[0]) << endl;
}
