#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, max = 0, next = 0;
  bool dmax = false;
  vector<int> a;
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (max == a[i]) dmax = true;
    if (max < a[i]) {
      next = max;
      max = a[i];
    } else if (next < a[i]) {
      next = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == max && dmax == false)
      cout << next << endl;
    else
      cout << max << endl;
  }
  return 0;
}
