#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, ct = 1, max, ind = 0, ind2, secmax, pt1, pt2, ans;
  cin >> n;
  int a[n], b[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  for (i = 1; i < n; i++) {
    if (b[i] == b[i - 1]) {
      ct = 0;
      break;
    }
    if (b[n - 1] == a[i]) {
      ind = i;
    }
  }
  if (ct == 1) {
    max = b[n - 1];
    ind2 = n - 2;
    secmax = b[n - 2];
    pt1 = ind - 1;
    pt2 = ind + 1;
    while (1) {
      ans = 0;
      if (pt1 != -1) {
        if (a[pt1] == secmax) {
          ans = 1;
          pt1--;
          ind2--;
          if (ind2 == -1) {
            break;
          }
          secmax = b[ind2];
        }
      }
      if (ans == 0) {
        if (pt2 != n) {
          if (a[pt2] == secmax) {
            ans = 1;
            pt2++;
            ind2--;
            if (ind2 == -1) {
              break;
            }
            secmax = b[ind2];
          }
        }
      }
      if (!ans) {
        ct = 0;
        break;
      }
    }
  }
  if (ct) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
