program ledf;
uses math;
var wall:array[1..100000,1..10000] of byte;
  a:array[1..100000] of integer;
  b:array[1..100000] of byte;
m,n,i,j,ob,ukdos,k,min:integer;

procedure binary(broj:integer; var b:array of byte);
var j:integer;
  begin
          for j:=1 to n do
              begin
                b[j]:=broj mod 2;
                broj:=broj div 2;
              end;
  end;
begin
  min:=0;
  ukdos:=0;
  read(n,m);
  for i:=1 to n do
    readln(a[i]);
  for k:=0 to (2**n)-1 do
      begin
        binary(k,b);
        for i:=1 to n do
          for j:=1 to m do
            if j<=a[i] then
                wall[i,j]:=b[i]
            else
                  wall[i,j]:=1-b[i];
        ukdos:=0;
        for j:=1 to m do
        begin
          ob:=0;
          for i:=1 to n do
            if wall[i,j] = 1 then
              ob:=ob+1;
          ukdos:=ukdos+ob*(n-ob);
        end;
        if min=0 then
          min:=ukdos
        else
          if ukdos < min then
            min:=ukdos;
      end;
  write(min);
end.