#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int *mx = max_element(a, a + n);
  int ind = 0;
  for (long long int i = 0; i < n; i++) {
    if (a[i] == *mx) ind = i;
  }
  if (ind == 0) {
    for (long long int i = 0; i < n - 1; i++) {
      if (a[i + 1] > a[i]) {
        cout << "NO" << endl;
        return;
      }
    }
    cout << "YES" << endl;
  }
  int j = ind + 1;
  int i = ind - 1;
  if (ind > 0 && ind != n - 1) {
    while (i >= 0 && j < n) {
      if (j < n) {
        if (a[j + 1] > a[j] && (j + 1) != n) {
          cout << "NO" << endl;
          return;
        } else
          j++;
      }
      if (i > 0) {
        i--;
        if (a[i] > a[i + 1]) {
          cout << "NO" << endl;
          return;
        }
      }
    }
    cout << "YES" << endl;
  } else if (ind == n - 1) {
    while (i > 0) {
      if (i > 0) {
        i--;
        if (a[i] > a[i + 1]) {
          cout << "NO" << endl;
          return;
        }
      }
    }
    cout << "YES" << endl;
  }
}
int main() {
  long long int t = 1;
  while (t-- > 0) {
    solve();
  }
}
