#include <bits/stdc++.h>
using namespace std;
void Ans(bool x) {
  if (x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
const long long int INF = 1001001001;
const long long int mod = 1000000007;
int main() {
  long long int n;
  cin >> n;
  long long int a[n];
  long long int m = 0;
  long long int o = 0;
  long long int c = INF;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    if (m <= a[i] && c != i) {
      o = m;
      c = i;
      m = max(m, a[i]);
    }
  }
  for (int i = 0; i < (int)(n); i++) {
    if (a[i] != m) {
      cout << m << endl;
    } else {
      cout << o << endl;
    }
  }
}
