https://www.acmicpc.net/problem/14719
H, W = map(int, input().split())
lst = list(map(int, input().split()))
ans = 0
for h in range(1, H+1):
start = -1
for w in range(W):
if lst[w] >= h:
if start >= 0:
# 범위 추가
ans += w - start - 1
# 초기화
start = w
print(ans)