#include <bits/stdc++.h>
using namespace std;
int n;
struct ss {
  int x, index;
};
ss c[200050];
int a[200050];
bool cmp(ss x, ss y) { return x.x < y.x; }
int find(int x) {
  int left = 1;
  int right = n;
  while (left <= right) {
    int mid = (left + right) / 2;
    if (c[left].x == x) return c[left].index;
    if (c[mid].x < x) {
      left = mid + 1;
    } else {
      if (c[right].x == x) return c[right].index;
      if (c[mid].x == x) return c[mid].index;
      right = mid + 1;
    }
  }
  if (c[left].x == x) return c[left].index;
  if (c[right].x == x) return c[right].index;
}
int main() {
  cin >> n;
  int flag = -1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ss temp;
    temp.index = i;
    temp.x = a[i];
    c[i] = temp;
    if (a[i] == n) flag = i;
  }
  sort(c, c + n, cmp);
  bool check = true;
  int left = flag - 1;
  int right = flag + 1;
  for (int i = n - 1; i >= 1; i--) {
    int pos = find(i);
    if (pos == left)
      left--;
    else if (pos == right)
      right++;
    else {
      check = false;
      break;
    }
  }
  if (check)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
