#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &s) {
  s = 0;
  register char ch = getchar();
  register int w = 0;
  while (!isdigit(ch)) w |= ch == '-', ch = getchar();
  while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  if (w) s = -s;
}
namespace Sakii {
const int maxn = 2e5 + 19;
int n, a[maxn];
inline void main() {
  read(n);
  for (int i = 1; i <= n; i++) read(a[i]);
  bool f = false;
  for (int i = 2; i <= n; i++) {
    if (a[i] < a[i - 1] && !f) f = true;
    if (f) {
      if (a[i] > a[i - 1]) {
        printf("NO\n");
        return;
      }
    }
  }
  printf("YES\n");
  return;
}
}  // namespace Sakii
int main() {
  Sakii::main();
  return 0;
}
