var
n,k,i,j:longint;
bit:array[1..32] of longint;
a:array[1..100000] of longint;
function work(x:longint):boolean;
var
i,j:longint;
q:boolean;
begin
fillchar(bit,sizeof(bit),0);
q:=false;
for i:=1 to x do
for j:=1 to k do
inc(bit[j],(a[i] shr (j-1)) and 1);
for i:=1 to k-1 do
if bit[i]<>bit[i+1] then break;
if (i=k-1)and(bit[k-1]=bit[k]) then q:=true;
for i:=x+1 to n do
begin
for j:=1 to k do
dec(bit[j],(a[i-x] shr (j-1))and 1);
for j:=1 to k do
inc(bit[j],(a[i] shr (j-1))and 1);
for j:=1 to k-1 do
if bit[j]<>bit[j+1] then break;
if (j=k-1)and(bit[k-1]=bit[k]) then begin q:=true; break; end;
end;
work:=q;
end;
begin
assign(input,'balline.in'); reset(input);
assign(output,'balline.out'); rewrite(output);
readln(n,k);
for i:=1 to n do
readln(a[i]);
for i:=n downto 1 do
begin
if work(i) then
begin
writeln(i);
close(input); close(output);
halt;
end;
end;
writeln(0);
close(input); close(output);
end.