#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 + 2e5;
const int INF = 0x3f3f3f;
int ans, ma, a[MAXN], n;
int main() {
  cin.tie(0);
  cin >> n;
  for (int i = (0), _b = (n); i < _b; ++i) cin >> a[i];
  for (int i = (0), _b = (n); i < _b; ++i) {
    if (a[i] < ma) ans = 1;
    if (ans == 1 && a[i] > ma) {
      cout << "NO";
      return 0;
    }
    ma = a[i];
  }
  cout << "YES";
  return 0;
}
