#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> A(n, 0), B(n, 0);
  for (int i = 0; i < (int)(n); i++) {
    cin >> A.at(i);
    B.at(i) = A.at(i);
  }
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  int MAX = B.at(0);
  int MAXsecond = MAX;
  for (int i = 0; i < (int)(n); i++) {
    if (MAX != B.at(i)) {
      MAXsecond = B.at(i);
      break;
    }
  }
  for (int i = 0; i < (int)(n); i++)
    (A.at(i) == MAX) ? cout << MAXsecond << endl : cout << MAX << endl;
}
