using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static long NN => long.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, p) = (c[0], c[1]); var h = NList; var dp1 = 0L; var dp2 = long.MaxValue / 2; var dp3 = long.MaxValue / 2; for (var i = 1; i < n; ++i) { var ndp1 = Math.Min(dp1, dp2) + Math.Max(0, h[i] - h[i - 1]); var ndp2 = Math.Min(dp1, Math.Min(dp2, dp3)) + p; var ndp3 = Math.Min(dp2, dp3) + Math.Max(0, h[i - 1] - h[i]); dp1 = ndp1; dp2 = ndp2; dp3 = ndp3; } WriteLine(Math.Min(dp1, Math.Min(dp2, dp3))); } }