#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v(n);
    int maxx = 0;
    int index = -1;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      if (v[i] >= maxx) {
        maxx = v[i];
        index = i;
      }
    }
    int r = index + 1, l = index - 1;
    bool ok = true;
    while (maxx > 0) {
      if (v[r] == maxx - 1) {
        r++;
        maxx--;
      } else if (v[l] == maxx - 1) {
        l--;
        maxx--;
      } else if (v[r] != maxx - 1 && v[l] != maxx - 1) {
        ok = false;
        break;
      }
      if (r >= n && l < 0) break;
    }
    if (ok == true)
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
}
