#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> pos(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  int l = pos[n] - 1;
  int r = pos[n] + 1;
  for (int i = n - 1; i >= 1; i--) {
    if (pos[i] != l && pos[i] != r) {
      cout << "NO\n";
      return 0;
    }
    if (pos[i] == l) {
      l--;
    } else {
      r++;
    }
  }
  cout << "YES\n";
}
