extension String: CollectionType {
    func toInts() -> [Int64] {
        return self.split(" ").map {Int64($0)!}
    }
    
    func toUInts() -> [UInt64] {
        return self.split(" ").map {UInt64($0)!}
    }
    
    func toStrings() -> [String] {
        return self.split(" ")
    }
}

let values = readLine()!.toUInts()
let N = Int(values[0])
let x: UInt64 = values[1]

var cs = readLine()!.toUInts()
var count: UInt64 = 0

if x < cs[0] {
    count += cs[0] - x
    cs[0] = x
}

(0 ..< N - 1).forEach { i in
    if x < cs[i] + cs[i + 1] {
        count += cs[i + 1] + cs[i] - x
        cs[i + 1] = x - cs[i]
    }
}

print(count)
