#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int ans[n];
  priority_queue<int> que;
  for (int i = 0; i < (n); i++) {
    int x;
    cin >> x;
    a[i] = x;
  }
  int max = 0;
  int second = 0;
  int maxnum = 0;
  for (int i = 0; i < (n); i++) {
    if (max < a[i]) {
      second = max;
      max = a[i];
      maxnum = i;
    }
  }
  for (int i = 0; i < (n); i++) {
    if (i != maxnum) {
      ans[i] = max;
    } else {
      ans[i] = second;
    }
  }
  for (int i = 0; i < (n); i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
