#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  vector<int> v(a), b(a);
  int tmp;
  for (int i = 0; i < a; i++) {
    cin >> v[i];
    b[i] = v[i];
  }
  sort(v.begin(), v.end());
  if (v[a - 1] == v[a - 2]) {
    for (int i = 0; i < a; i++) cout << v[a - 1] << endl;
  } else
    for (int i = 0; i < a; i++) {
      if (v[a - 1] == b[i]) tmp = i;
    }
  for (int i = 0; i < a; i++) {
    if (tmp == i)
      cout << v[a - 2] << endl;
    else
      cout << v[a - 1] << endl;
  }
}
