#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, kl = 0;
  cin >> n;
  vector<int> a, b;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x == n) {
      kl = 1;
      continue;
    }
    if (kl == 0)
      a.push_back(x);
    else
      b.push_back(x);
  }
  int l = a.size();
  for (int i = 0; i < l - 1; i++)
    if (a[i] > a[i + 1]) {
      cout << "NO";
      return 0;
    }
  l = b.size();
  for (int i = 0; i < l - 1; i++)
    if (b[i] < b[i + 1]) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
  return 0;
}
