#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int save[maxn], pos[maxn], l[maxn], r[maxn];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", save + i), pos[save[i]] = i;
  for (int i = 1; i <= n; i++) l[i] = i - 1, r[i] = i + 1;
  sort(save + 1, save + n + 1);
  int s = pos[save[n]];
  int judge = 1;
  for (int i = n - 1; i >= 1; i--) {
    if (pos[save[i]] == l[s]) {
      l[s] = l[l[s]];
    } else if (pos[save[i]] == r[s]) {
      r[s] = r[r[s]];
    } else {
      judge = 0;
      break;
    }
  }
  if (judge)
    printf("YES\n");
  else
    printf("NO");
  return 0;
}
