#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> nums(n);
  for (int i = 0; i < n; i++) cin >> nums[i];
  long long temp = *max_element(nums.begin(), nums.end());
  for (int i = 0; i < n; i++) {
    if (nums[i] == temp) {
      nums[i] = 0;
      cout << *max_element(nums.begin(), nums.end()) << endl;
      nums[i] = temp;
    } else
      cout << temp << endl;
  }
  return 0;
}
