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