#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, a[200100], mx = 0, pos, f = 0;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] > mx) {
      mx = a[i];
      pos = i;
    }
  }
  for (i = pos + 1; i <= n; i++) {
    if (a[i] > a[i - 1]) f = 1;
  }
  for (i = 1; i < pos; i++) {
    if (a[i] > a[i + 1]) f = 1;
  }
  if (f == 1)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
