/// Swift5 -> Swift2.2
extension String {
    // split(separator:maxSplits:omittingEmptySubsequences:)
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map(String.init)
    }
}
extension Array {
    // init(repeating:count:)
    init(repeating: Element, count: Int) {
       self.init(count: count, repeatedValue: repeating)
    }
}
/// end

let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let K = input[1]
let h = [0] + readLine()!.split(separator: " ").map { Int($0)! }

var dp = Array(repeating: Int.max, count: N + 1)
dp[1] = 0

for i in 1 ... N {
    for j in 1 ... K {
        guard i + j <= N else { break }
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
    }
}

print(dp.last!)
