#include <bits/stdc++.h>
using namespace std;
int max(int a[]);
int main() {
  int i, j, k, l = 0, n, m, f = 0, c;
  cin >> n;
  int a[n + 1], b[n + 1];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  for (i = 0; i < n; i++) {
    if (b[n - 1] == a[i]) {
      k = i;
      break;
    }
  }
  i = k - 1;
  j = k + 1;
  l = n - 2;
  while (1) {
    if (i == -1 && j == n) {
      f = 0;
      break;
    }
    if (a[i] == b[l] && i != -1) {
      i--;
      l--;
    } else if (a[j] == b[l] && j != n) {
      j++;
      l--;
    } else {
      f = 1;
      break;
    }
  }
  if (f == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
