#include <bits/stdc++.h>
using namespace std;
bool compare_pair(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second > b.second;
  } else {
    return true;
  }
}
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int argmax_1 = 0;
  int argmax_2 = n - 1;
  for (int i = 0; i < n; i++) {
    if (a[argmax_1] < a[i]) {
      argmax_1 = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[argmax_2] < a[i] && a[i] <= a[argmax_1] && i != argmax_1) {
      argmax_2 = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i != argmax_1) {
      cout << a[argmax_1] << endl;
    } else {
      cout << a[argmax_2] << endl;
    }
  }
  return 0;
}
