#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
const long long maxn = 2e5 + 7;
long long a[maxn];
long long b[maxn];
bool f(long long l, long long r, long long i) {
  if (l == r) return 1;
  if (a[l] == b[i]) {
    return f(l + 1, r, i + 1);
  }
  if (a[r] == b[i]) return f(l, r - 1, i + 1);
  return 0;
}
int32_t main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  if (f(1, n, 1)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
