#include <bits/stdc++.h>
using namespace std;
int N, A, mayorA, mayorS;
vector<int> values;
set<int> numbers;
int main() {
  cin >> N;
  while (N--) {
    cin >> A;
    values.push_back(A);
    numbers.insert(A);
  }
  set<int>::iterator mayor = numbers.end();
  mayor--;
  mayorA = *mayor;
  mayorS = mayorA;
  if (numbers.size() > 1) {
    mayor--;
    mayorS = *mayor;
  }
  for (int v : values) {
    if (v != mayorA) {
      cout << mayorA << '\n';
    } else {
      cout << mayorS << '\n';
    }
  }
  return 0;
}
