#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

int main(){
  int n;
  cin >> n;

  vector<int> a(n), cp_a(n);

  for(int i=0; i<n; ++i){
    cin >> a[i];
    cp_a[i] = a[i];
  }

  sort(cp_a.begin(), cp_a.end(), greater<int>());

  int mx, mx1;
  bool flag = false;
  for(int i=0; i<cp_a.size(); ++i){
    mx = cp_a[0];
    if(cp_a[0] > cp_a[i]){
      mx1 = cp_a[i];
      flag = true;
      break;
    }
  }
  for(int i=0; i<n; ++i){
    if(flag){
      if(mx != a[i]) cout << mx << endl;
      if (mx == a[i]) cout << mx1 << endl;
    }
    return 0;
    else cout << mx << endl;
  }

  
  return 0;
}