#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> numbers(N);
  int max_number = 0;
  int max_index = 0;
  int n;
  for (int i = 0; i < N; i++) {
    cin >> numbers.at(i);
    if (max_number < numbers.at(i)) {
      max_number = numbers.at(i);
      max_index = i;
    }
  }
  for (int i = 1; i < N; i++) {
    if (i == max_index) {
      int m = 0;
      int m_index = 0;
      for (int j = 0; j < N; j++) {
        if (i == j) {
          continue;
        }
        if (m < numbers.at(j)) {
          m = numbers.at(j);
          m_index = j;
        }
      }
      cout << m << endl;
    } else {
      cout << max_number << endl;
    }
  }
}
