#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n;
  vector<vector<long long>> x;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    vector<long long> temp(2, 0);
    cin >> temp[0];
    temp[1] = i;
    x.push_back(temp);
  }
  sort(x.begin(), x.end(),
       [](vector<long long>& a, vector<long long>& b) { return a[0] < b[0]; });
  vector<long long> output;
  for (long long i = 0; i < n; i++) {
    if (x[i][1] == n - 1)
      output.push_back(x[n - 2][0]);
    else
      output.push_back(x[n - 1][0]);
  }
  for (long long i = 0; i < n; i++) cout << output[i] << endl;
  return 0;
}
