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