#include<iostream>
#include<cstdio>
using namespace std;
const int MA=1005;
int stack[MA];
int a[MA];
int top=-1;
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
int cur=1;//cur为进过栈的数字最大值+1,初始cur为1
for(int i=1;i<=n;i++){
while(stack[top]<a[i]){ //进栈 cur 到 a[i]
stack[++top]=cur++;
}
if(stack[top]==a[i]) top--;//出栈a[i]
else{
printf("NO
");
return 0;
}
}
printf("YES
");
return 0;
}