program malovremena;
var
niz:array[1..1000] of integer;
tabela:array[1..1000,1..1000] of longint;
t,i,brojacb,brojacc,n,m,u,x:integer;
begin
read(n,m);
for t:=1 to n do
    begin
    read(niz[t]);
    end;
for t:=1 to n do
    begin
    for i:=1 to m  do
    begin
     if niz[t]=m then tabela[t,i]:=2
     else
         if niz[t] > 0 then
            begin
            tabela[t,i]:=1;
            niz[t]:=niz[t]-1;
            brojacc:=brojacc+1;
            end
            else
            begin
            tabela[t,i] :=0;
            brojacb:=brojacb+1;
            end;
     end;

    end;
 if brojacc>brojacb then
    begin
    for t:=1 to n do
    begin
         for i:=1 to m do
             begin
             if tabela[t,i] = 2 then tabela[t,i]:=1;

             end;
    end;
    end
    else
    begin
    for t:=1 to n do
    begin
         for i:=1 to m do
             begin
             if tabela[t,i]=2 then tabela[t,i]:=0;
             end;
    end;
    end;
u:=0;
for t:=1 to m do
    begin
    brojacc:=0;
    brojacb:=0;
    for i:=1 to n do
        begin
        if tabela[i,t]=0 then brojacb:=brojacb+1
        else brojacc:=brojacc+1;
        end;
    x:=brojacc*brojacb;
    u:=u+x;
    end;
write(u);


end.