#include <iostream>
using namespace std;

bool comp(int a, int b) 
{ 
    return (a < b); 
} 

int main() {
  int n,c,d;
  int b;
  cin>>n;
  int a[n+1];

  for (int i=1;i<=n;i++){
    cin>>a[i];
  }
  for (int i=1;i<=n;i++){
    if (i==n-1){
      c=a[n];
      a[n]=a[i];
      a[i]=c;
      break;
    }
    b=a[i];
    for (int k=i;k<=n;k++){
      if (a[k]>b){
        b=a[k];
      }
    }
    if (b!=a[i]){
      for (int j=i+1;j<=n;j++){
        if (b==a[j]){
          d=j;
        }
      }
      c=a[i];
      a[i]=a[d];
      a[d]=c;
      break;
      
    }
  }
  for (int i=1;i<=n;i++){
    cout<<a[i]<<" "; 
  }
  return 0;
  
}