#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> a;
  cin >> n;
  int mostLargestNum = 0;
  int secondLargestNum = 0;
  bool largestJuhuku = false;
  for (int i = 0; i < n; i++) {
    int input;
    cin >> input;
    a.push_back(input);
    if (input > mostLargestNum) {
      secondLargestNum = mostLargestNum;
      mostLargestNum = input;
      largestJuhuku = false;
    }
    if (input > secondLargestNum && input < mostLargestNum) {
      secondLargestNum = input;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == mostLargestNum) {
      cout << secondLargestNum << endl;
    } else {
      cout << mostLargestNum << endl;
    }
  }
  return 0;
}
