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