#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  bool f = true;
  int l = 0, r = n - 1;
  for (int i = 1; i <= n; i++) {
    if (a[l] == i)
      l++;
    else if (a[r] == i)
      r--;
    else {
      f = false;
      break;
    }
  }
  if (f == false)
    printf("NO");
  else
    printf("YES");
  return 0;
}
