#include <bits/stdc++.h>
using namespace std;
const int maxN = 200000;
int main() {
  long long N;
  long long A[maxN];
  cin >> N;
  long long firstMax = 0;
  long long secondMax = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] > firstMax) {
      secondMax = firstMax;
      firstMax = A[i];
    } else if (A[i] > secondMax) {
      secondMax = A[i];
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i] = firstMax) {
      cout << secondMax << endl;
    } else {
      cout << firstMax << endl;
    }
  }
}
