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