program malovremena;
var
niz:array[1..100] of integer;
tabela:array[1..100,1..100] of longint;
t,i,brojacb,brojacc,n,m,u: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[1]:=niz[1]-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[t,i]=1 then brojacc:=brojacc+1
        else brojacb:=brojacb+1;
        end;
    u:=u+brojacc*brojacb
    end;
write(u);


end.