#include<bits/stdc++.h>
#define int long long
using namespace std;
stack s;
const int N=1000+5;
int a[N],vis[N];
signed main(){
int n,t=1;
scanf("%lld",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i]);
for(int i=1;i<=n;i++)
if(a[i]>=t){
while(t<=a[i]){
s.push(t);
t++;
}
s.pop();
}
else if(s.top()==a[i])
s.pop();
else{
printf("NO");
return 0;
}
printf("YES");
return 0;
}