#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[20005];
  pair<int, int> p[20005];
  cin >> n;
  int max1 = -1, max2 = -1, ind1, ind2;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    p[i] = make_pair(a[i], i);
  }
  sort(p, p + n);
  max1 = p[n - 1].first;
  max2 = p[n - 2].first;
  ind1 = p[n - 1].second;
  ind2 = p[n - 2].second;
  for (int i = 0; i < n; i++) {
    if (a[i] == max1 && i == ind1)
      cout << max2 << endl;
    else
      cout << max1 << endl;
  }
}
