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