#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int mx = 0, mx2 = -1;
  cin >> n;
  vector<int> a(n);
  for (int i = (0), iformax = (n); i < iformax; i++) {
    cin >> a[i];
    if (mx < a[i]) {
      mx = a[i];
    }
    if (mx2 < a[i <= mx]) {
      mx2 = a[i];
    }
  }
  for (int j = (0), jformax = (n); j < jformax; j++) {
    if (a[j] = mx) {
      cout << mx2 << '\n' << endl;
    } else {
      cout << mx << '\n' << endl;
    }
  }
  return 0;
}
