let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, x) = (input[0], input[1])
var a = readLine()!.characters.split(" ").map{Int(String($0))!}
var ans = 0
for i in 1..<N {
    let tmp = max(a[i-1] + a[i] - x, 0)
    a[i] -= tmp
    ans += tmp
}
print(ans)