#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, i, j, k, u;
  cin >> n;
  vector<pair<int, int> > vect;
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    vect.push_back(make_pair(x, i));
  }
  sort(vect.begin(), vect.end());
  int l, r, flag = 0;
  l = vect[n - 1].second;
  r = l;
  for (i = n - 2; i >= 0; i--) {
    u = vect[i].second;
    if (l - u == 1)
      l = u;
    else if (u - r == 1)
      r = u;
    else {
      flag = 1;
      break;
    }
  }
  if (flag == 1)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
  return 0;
}
