#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n], count[n], top[n];
  for (int i = 0; i < n; ++i) cin >> arr[i];
  int mx = arr[0];
  int ind = 0;
  for (int i = 1; i < n; ++i)
    if (arr[i] > mx) {
      mx = arr[i];
      ind = i;
    }
  int l = ind - 1, r = ind + 1;
  while (l >= 0 || r < n) {
    if (l >= 0 && r < n) {
      if (arr[l] < mx && arr[r] < mx) {
        int temp = max(arr[l], arr[r]);
        if (temp == arr[l])
          l--;
        else
          r++;
        mx = temp;
      } else
        break;
    } else if (l >= 0) {
      if (arr[l] < mx) {
        mx = arr[l];
        l--;
      } else
        break;
    } else if (r < n) {
      if (arr[r] < mx) {
        mx = arr[r];
        r++;
      } else
        break;
    }
  }
  if (l == -1 && r == n)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
