#include <bits/stdc++.h>
using namespace std;
int n, l, r, pos, a[200005];
inline int read() {
  int red = 0, f_f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f_f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') red = red * 10 + ch - '0', ch = getchar();
  return red * f_f;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    if (a[i] == n) pos = i;
  }
  l = r = pos;
  for (int i = n - 1; i > 0; i--) {
    if (l != 0 && a[l - 1] == i) {
      l--;
    } else if (r != n && a[r + 1] == i) {
      r++;
    } else {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
