var n,k,p,i,cnt,min,stop,disk1,disk2,next,pre:longint;
a,b:array[-10..10000]of longint;
function f(x,y,p:longint):longint;
var cnt:longint;
begin
cnt:=0;
while x<>y do begin
inc(cnt);
inc(x,p);
if x=101 then x:=1;
if x=0 then x:=100;
end;
exit(cnt);
end;
procedure swap(var a,b:longint);
var t:longint;
begin
t:=a; a:=b; b:=t;
end;
procedure qsort(l,r:longint);
var i,j,mid:longint;
begin
i:=l; j:=r; mid:=(a[(l+r) div 2]);
repeat
while (a[i])<mid do inc(i);
while (a[j])>mid do dec(j);
if i<=j then begin
swap(a[i],a[j]);
inc(i);
dec(j);
end;
until i>j;
if i<r then qsort(i,r);
if j>l then qsort(l,j);end;
begin
readln(n,k);
for i:=1 to n do read(a[i]);
qsort(1,n);
a[0]:=a[n];
min:=maxlongint;
for i:=1 to n do begin
next:=(i+1)mod n;
pre:=(i+n-1)mod n;
disk1:=f(k,a[i],1);
if f(k,a[next],1)>disk1 then
disk1:=disk1+f(a[i],a[next],-1);
disk2:=f(k,a[i],-1);
if f(k,a[pre],-1)>disk2 then
disk2:=disk2+f(a[i],a[pre],1);
if disk1<min then min:=disk1;
if disk2<min then min:=disk2;
end;
writeln(min);
close(input);
close(output);
end.