#include <bits/stdc++.h>
using namespace std;
const int INF = 1e+9;
const int MOD = 1e+9 + 7;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int i_top, i_second;
  int m = 0;
  for (long long i = 0; i < (long long)(N); i++) {
    if (m <= A[i]) {
      i_second = i_top;
      i_top = i;
      m = A[i];
    }
  }
  for (long long i = 0; i < (long long)(N); i++) {
    if (A[i] == m)
      cout << A[i_second] << endl;
    else
      cout << m << endl;
  }
}
