#include <bits/stdc++.h>
using namespace std;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int mx1 = 0, mx2 = 0;
  cin >> A[0];
  mx1 = 0;
  for (int i = 1; i < N; i++) {
    cin >> A[i];
    if (A[mx1] < A[i]) {
      mx2 = mx1;
      mx1 = i;
    } else {
      if (A[mx2] < A[i]) {
        mx2 = i;
      }
    }
  }
  for (int i = 0; i < (int)(N); i++) {
    if (i == mx1) {
      cout << A[mx2] << endl;
    } else {
      cout << A[mx1] << endl;
    }
  }
}
