#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N;
  cin >> N;
  vector<int> A(N);
  int max = 0, secondmax = 0;
  for (int i = 0; i < N; ++i) {
    cin >> A.at(i);
    if (A.at(i) >= max) {
      secondmax = max;
      max = A.at(i);
    }
  }
  for (int i = 0; i < N; ++i) {
    if (A.at(i) == max) {
      cout << secondmax << " " << endl;
    } else {
      cout << max << " " << endl;
    }
  }
}
