#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<int>::iterator maxIt = max_element(A.begin(), A.end());
  int maxIndex = distance(A.begin(), maxIt);
  int max = A[maxIndex];
  for (int i = 0; i < N; i++) {
    if (i != maxIndex)
      cout << max << endl;
    else {
      int max2 = 0;
      for (int j = 0; j < N; j++) {
        if (j == i)
          continue;
        else if (A[j] > max2)
          max2 = A[j];
      }
      cout << max2 << endl;
    }
  }
  return 0;
}
