n,k=gets.strip.split.map(&:to_i)
a=gets.strip.split.map(&:to_i)
i=0
count=0
while i<n && a[i]==0
  i+=1
end
while i<n
  count+=1
  j=i
  while j<n && a[j]>0
    a[j]-=1
    j+=1
  end
  
  while i<n && a[i]==0
    i+=1
  end
end
puts count
