#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  queue<int> s2, s1;
  vector<int> s11;
  int a, b, c, co = 0;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    if (arr[i] == n) co++;
    if (co == 0)
      s11.push_back(arr[i]);
    else if (co && arr[i] != n)
      s2.push(arr[i]);
  }
  int x = s11.size();
  for (int i = x - 1; i >= 0; --i) s1.push(s11[i]);
  stack<int> store;
  store.push(n);
  for (int i = 0; i < n; ++i) {
    if (s1.size() != 0 && s2.size() != 0) {
      a = s1.front();
      b = s2.front();
      c = store.top();
      if ((c - a) == 1) {
        store.push(a);
        s1.pop();
      } else if ((c - b) == 1) {
        store.push(b);
        s2.pop();
      } else
        break;
    } else if (s1.size() == 0) {
      b = s2.front();
      c = store.top();
      if ((c - b) == 1 && b != 0) {
        store.push(b);
        s2.pop();
      } else
        break;
    } else if (s2.size() == 0) {
      a = s1.front();
      c = store.top();
      if ((c - a) == 1 && a < n) {
        store.push(a);
        s1.pop();
      } else
        break;
    }
  }
  if (store.size() == n)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
