#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m = 0, x = 0;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < n; i++) {
    if (x <= A[i]) {
      m = 0;
      for (int j = 0; j < n; j++) {
        if (m < A[j]) {
          if (i != j) m = A[j];
        }
      }
      cout << m << endl;
      if (x < m) x = m;
    } else {
      cout << x << endl;
    }
  }
}
