#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int l, N, i=0;
  cin >> N;
  int vec[N];
  int g_max = 0;
  int max = 0;
  int sec_index = 0;
  int sec_max = 0;
  while(cin >> l){
    vec[i] = l;
    if (max < l){
      max = l;
      g_max = i;
    } else {
      if (sec_max < l){
        sec_max = l;
    }
    
    i++;
  }

  for(i = 0; i < N; i++){
    max = 0;
    if(i == g_max){
      max = sec_max;
    } else {
      max = vec[g_max];
    }
    cout << max << "\n";
  }
}