#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int main() {
  int a, n, m = -1, m2 = -1, midx = -1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (max(m, a) == a) {
      midx = i;
      m = a;
    } else if (max(m2, a) == a) {
      m2 = a;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == midx) {
      if (m2 == -1) {
        cout << m << endl;
      } else {
        cout << m2 << endl;
      }
    } else {
      cout << m << endl;
    }
  }
  return 0;
}
