#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long int n;
  cin >> n;
  long long int arr[n];
  set<long long int> s;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
    s.insert(arr[i]);
  }
  for (long long int i = 0; i < n; i++) {
    s.erase(arr[i]);
    cout << *s.rbegin() << "\n";
    s.insert(arr[i]);
  }
  return 0;
}
