#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int m = *max_element(a.begin(), a.end());
  bool flag = true, ans = true;
  if (m == a[0]) flag = false;
  for (int i = 1; i < n; i++) {
    if (a[i] < a[i - 1] && flag) {
      ans = false;
    } else if (a[i] > a[i - 1] && !flag) {
      ans = false;
    }
    if (a[i] == m) {
      flag = false;
    }
  }
  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
