hs = gets.split.map{|i| i.to_i }

sum = 0

hs.each do |i|
  if hs[i] > 0
    hs[i] -= 1
    sum += 1
    for(j=0; j+i+1 < hs.length; j++) do
      break if(hs[i+j+1] <= 0)
      hs[i+j+1] -= 1
      sum += 1
    end
  end
end
  
  puts sum