#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, mn = 0, le = 0;
  cin >> t;
  int arr[t];
  for (int i = 1; i <= t; i++) {
    cin >> arr[i];
    if (arr[i] >= mn) {
      le = mn;
      mn = arr[i];
    }
  }
  for (int i = 1; i <= t; i++) {
    if (arr[i] == mn) {
      printf("%d\n", le);
    } else {
      printf("%d\n", mn);
    }
  }
  return 0;
}
