#include <bits/stdc++.h>
using namespace std;
void print_vec(vector<int>& v) {
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  vector<int> v2(v);
  vector<int>::iterator it = max_element(v.begin(), v.end());
  sort(v.begin(), it);
  sort(it, v.end(), greater<int>());
  bool flag = true;
  for (int i = 0; i < n; i++)
    if (v[i] != v2[i]) flag = false;
  if (flag)
    cout << "YES\n";
  else
    cout << "NO\n";
}
