#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1;
int a[N], p[N];
int main() {
  int i, j, k, n, t;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
    p[a[i]] = i;
  }
  int l = p[n], r = p[n];
  for (i = n - 1; i > 0; --i) {
    if (p[i] == l - 1)
      --l;
    else if (p[i] == r + 1)
      ++r;
    else {
      cout << "NO";
      exit(0);
    }
  }
  cout << "YES\n";
}
