#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int arr[N], tempp[N], n;
int main() {
  cin >> n;
  int prevMax = 0, curMax = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    tempp[i] = arr[i];
  }
  sort(tempp, tempp + n);
  prevMax = tempp[n - 2];
  curMax = tempp[n - 1];
  for (int i = 0; i < n; i++) {
    if (arr[i] == curMax)
      cout << prevMax << endl;
    else
      cout << curMax << endl;
  }
}
