#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v, v2;
  int counter, tmp, max, second, result;
  cin >> counter;
  for (int i = 0; i < counter; i++) {
    cin >> tmp;
    v.emplace_back(tmp);
  }
  max = *max_element(v.begin(), v.end());
  v2 = v;
  sort(v2.begin(), v2.end(), greater<int>());
  second = v2[1];
  for (int i = 0; i < counter; i++) {
    if (v[i] == max) {
      cout << second << endl;
    } else {
      cout << *max_element(v.begin(), v.end()) << endl;
    }
  }
  return 0;
}
