N, K = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)
dp = Array.new(N, 0)
1.step(N-1) do |i|
  p1 = i-1 >= 0 ? (H[i-1] - H[i]).abs + dp[i-1] : Float::INFINITY
  p2 = i-2 >= 0 ? (H[i-2] - H[i]).abs + dp[i-2] : Float::INFINITY
  dp[i] = [p1, p2].min
end
puts dp.last
