#include <bits/stdc++.h>
using namespace std;
int a[200009], pos[200009];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  int l = 0, r = 0, cur = pos[n], val = n;
  l = cur - 1, r = cur + 1;
  bool flag = 0;
  while (val > 1) {
    if ((l > 0 && (val - a[l]) == 1)) {
      val--;
      l--;
      continue;
    }
    if ((r <= n && (val - a[r]) == 1)) {
      val--;
      r++;
      continue;
    }
    flag = 1;
    break;
  }
  if (flag)
    cout << "NO\n";
  else
    cout << "YES\n";
}
