#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v;
  vector<int>::iterator it;
  int* arr = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    v.push_back(arr[i]);
  }
  for (int i = 0; i < n; i++) {
    it = find(v.begin(), v.end(), arr[i]);
    int temp = v[it - v.begin()];
    v[it - v.begin()] = -1;
    cout << *max_element(v.begin(), v.end()) << endl;
    v[it - v.begin()] = temp;
  }
  return 0;
}
