#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  cin >> n;
  vector<int> a(n);
  int ma = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ma = max(ma, a[i]);
  }
  int ma2 = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != ma) {
      ma2 = max(ma2, a[i]);
    }
  }
  if (ma2 == 0) ma2 = ma;
  for (int i = 0; i < n; i++) {
    if (a[i] != ma) {
      cout << ma << endl;
    } else {
      cout << ma2 << endl;
    }
  }
  return 0;
}
