#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vc(n);
  int max = 0, two = 0;
  for (int i = 0; i < n; i++) {
    cin >> vc.at(i);
    if (vc.at(i) >= max) {
      two = max;
      max = vc.at(i);
    }
  }
  for (int i = 0; i < n; i++) {
    if (vc.at(i) == max) {
      cout << two << endl;
    } else {
      cout << max << endl;
    }
  }
}
