#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int m = 0, mm = 0;
  queue<int> mi;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (m < a[i]) {
      mi.push(i);
      mm = m;
      m = a[i];
    } else if (mm < a[i]) {
      mm = a[i];
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i != mi.front() || mi.size() > 1) {
      cout << m << endl;
      mi.pop();
    } else {
      cout << mm << endl;
    }
  }
  return 0;
}
