program zadD;
var n, m, stari, i, a, z: Int32;
    o: array [1 .. 10000] of Int32;
    p: array [1 .. 10000] of Int32;
begin
    ReadLn(n, m);
    ReadLn(stari);
    for i := 1 to stari do
        o[i] := 1;
    for i := stari + 1 to m do
        o[i] := o;
    for i := 2 to n do
        begin
        Readln(a);
        if stari - a > m - a then
            begin
            for j := 1 to a do
            o[j] := o[j] + 1;
            end
        else
            begin
            for i := 1 downto a + 1 do
            o[j] := o[j] + 1;
            end;
        stari := a;
        end;
        z := 0;
    for i := 1 to m do
        z := z + o[i] * (n - o[i]);
    Writeln (z);
end.