#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ar[n];
  int maxi, flag = 0;
  for (int i = 0; i < n; ++i) {
    cin >> ar[i];
    if (ar[i] == n) maxi = i;
  }
  for (int i = 0; i < maxi; ++i) {
    if (ar[i] > ar[i + 1]) {
      flag = 1;
      break;
    }
  }
  if (flag == 0) {
    for (int i = maxi + 1; i < n - 1; ++i) {
      if (ar[i] < ar[i + 1]) {
        flag = 1;
        break;
      }
    }
  }
  if (flag == 0)
    cout << "YES";
  else
    cout << "NO";
}
