#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int tmp;
  int Max = 0;
  Max = *max_element(a.begin(), a.end());
  for (int i = 0; i < n; ++i) {
    if (a[i] != Max) {
      cout << Max << endl;
    } else {
      int num = i;
      tmp = a[i];
      a.erase(a.begin() + i);
      int subMax;
      subMax = *max_element(a.begin(), a.end());
      a[i] = tmp;
      cout << subMax << endl;
      a.insert(a.begin() + i, tmp);
    }
  }
}
