#include <bits/stdc++.h>
int v[200005];
int main() {
  int n, i, now;
  std::cin >> n;
  for (i = 1; i <= n; ++i) {
    std::cin >> now;
    v[now] = i;
  }
  int left(v[n]), right(v[n]);
  for (i = n - 1; i >= 1; --i) {
    if (v[i] != right + 1 && v[i] != left - 1) {
      return std::cout << "NO", 0;
    }
    if (v[i] == right + 1) {
      right++;
    } else
      left--;
  }
  return std::cout << "YES", 0;
}
