#include <bits/stdc++.h>
using namespace std;
int n;
int a[20000021];
multiset<int> s;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    s.insert(a[i]);
  }
  for (int i = 1; i <= n; i++) {
    s.erase(a[i]);
    multiset<int>::iterator it = s.end();
    it--;
    printf("%d\n", *it);
    s.insert(a[i]);
  }
  return 0;
}
