#include <bits/stdc++.h>
using namespace std;
int main() {
  int N = 0;
  cin >> N;
  vector<int> a(N);
  int max, maxsecond = 0;
  int maxs, maxseconds = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (max < a[i]) {
      max = a[i];
      maxs = i;
    } else if (maxsecond < a[i]) {
      maxsecond = a[i];
      maxseconds = i;
    }
  }
  for (int i = 0; i < N; i++) {
    if (i != maxs) {
      cout << max << endl;
    } else {
      cout << maxsecond << endl;
    }
  }
}
