def solve(arr,x):
if x == 1:
return "YES"
for i in (0,x-2):
if(arr[i+1]<arr[i]):
return "NO"
break
return "YES"
T = int(input())
arr = [int(x) for x in input().split()]
print(solve(arr,T))