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