program zzn;
var
p,q,i,j,ans:longint;
num,peo:array[1..100]of integer;
v:array[1..1000]of boolean;
procedure init;
begin
assign(input,'prison.in');
reset(input);
assign(output,'prison.out');
rewrite(output);
readln(p,q);
for i:=1 to q do read(peo[i]);
end;
procedure closef;
begin
close(input);
close(output);
end;
function work:longint;
var
s,sum,i,j,x,l:longint;
v:array[1..1000]of boolean;
begin
sum:=0;
fillchar(v,sizeof(v),0);
for i:=1 to q do
begin
x:=peo[num[i]];
v[x]:=true;
s:=0;
for j:=x-1 downto 1 do if v[j] then break else
begin
inc(s);
end;
for j:=x+1 to p do if v[j] then break else
inc(s);
inc(sum,s);
end;
exit(sum);
end;
procedure dep(x:integer);
var
i:longint;
begin
if x>q then
begin
i:=work;
if i<ans then ans:=i;
end;
for i:=1 to q do
if not(v[i]) then
begin
num[x]:=i;
v[i]:=true;
dep(x+1);
v[i]:=false;
end;
end;
procedure main;
begin
ans:=maxlongint;
fillchar(v,sizeof(v),0);
dep(1);
writeln(ans);
end;
begin
init;
main;
closef;
end.