#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int num = -1;
  int num2 = -1;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    num = max(A[i], num);
  }
  for (int i = 0; i < N; ++i) {
    if (A[i] == num) {
      for (int j = 0; j < N; ++j) {
        if (j == i) {
          continue;
        } else {
          num2 = max(A[j], num2);
        }
      }
      cout << num2 << endl;
      num2 = -1;
    } else {
      cout << num << endl;
    }
  }
}
