#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m1 = 0, m2 = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  for (int i = 1; i < n; i++) {
    if (a.at(i - 1) <= a.at(i))
      m1 = i;
    else if (a.at(m2) <= a.at(i))
      m2 = i;
  }
  for (int i = 0; i < n; i++) {
    if (i == m1)
      cout << a.at(m2) << endl;
    else
      cout << a.at(m1) << endl;
  }
}
