#include <bits/stdc++.h>
using namespace std;
bool check(int a, int b) {
  if (a > b) {
    return true;
  } else {
    return false;
  }
}
int main() {
  int *A;
  int *B;
  int N;
  int i;
  int pos;
  int point, score;
  cin >> N;
  A = new int[N];
  B = new int[N];
  for (i = 0; i < N; i++) {
    cin >> A[i];
    B[i] = A[i];
  }
  sort(B, B + N, check);
  for (i = 0; i < N; i++) {
    if (B[0] == A[i]) {
      cout << B[1] << endl;
    } else {
      cout << B[0] << endl;
    }
  }
  return 0;
}
