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