#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, in;
  cin >> n;
  vector<long long> v;
  for (int i = 0; i < n; i++) {
    cin >> in;
    v.push_back(in);
  }
  long long ans = *max_element(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    if (v[i] == ans) {
      long long val = INT_MIN;
      for (int j = 0; j < n; j++) {
        if (v[j] > val && v[j] < v[i]) val = v[j];
      }
      cout << val << endl;
    } else
      cout << ans << endl;
  }
  return 0;
}
