#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, i, temp, high;
  cin >> n;
  vector<int> a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  high = *max_element(a.begin(), a.end());
  for (i = 0; i < n; i++) {
    temp = a[0];
    a.erase(a.begin());
    if (temp == high) {
      cout << *max_element(a.begin(), a.end()) << endl;
    } else {
      cout << high << endl;
    }
    a.push_back(temp);
  }
  return 0;
}
