#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  vector<vector<long long int> > adj(n + 1, vector<long long int>(2, 0));
  vector<long long int> vis(n + 1, 0);
  vis[n] = 1;
  for (long long int i = 0; i <= n - 1; i++) {
    cin >> v[i];
  }
  for (long long int i = 0; i <= n - 1; i++) {
    if (i > 0) adj[v[i]][0] = v[i - 1];
    if (i < n - 1) adj[v[i]][1] = v[i + 1];
  }
  long long int fou = 0;
  for (long long int i = n; i >= 1; i--) {
    if (!vis[i]) {
      fou = 1;
      break;
    }
    vis[adj[i][0]] = 1;
    vis[adj[i][1]] = 1;
  }
  if (fou)
    cout << "NO" << '\n';
  else
    cout << "YES" << '\n';
  return 0;
}
