#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  const int num = N;
  int A[num], B[num];
  for (int i = 0; i < num; i++) {
    cin >> A[i];
  }
  A[num] = B[num];
  for (int s = 0; s < num - 1; s++) {
    for (int t = s + 1; t < num; t++) {
      if (B[t] > B[s]) {
        int tmp = B[t];
        B[t] = B[s];
        B[s] = tmp;
      }
    }
  }
  for (int u = 0; u < num; u++) {
    if (A[u] == B[0] && B[0] == B[1]) {
      cout << B[0] << endl;
    } else if (A[u] == B[0]) {
      cout << B[1] << endl;
    } else {
      cout << B[0] << endl;
    }
  }
  return 0;
}
