uses math;
type rgb=record
 r,g,b,num:longint;
end;
const mx=255;
Var a,s:array[-1..mx+1,-1..mx+1,-1..mx+1]of longint;
    i,j,u,w,x,y,z,k,d,n,l,r,c:longint;
    was:boolean;
    h:array[0..100333]of rgb;
 function can(d:integer):boolean;
   var i,j,u:integer;
     begin
       for i:=0 to mx-d do
         for j:=0 to mx-d do
           for u:=0 to mx-d do
             if
             s[i+d,j+d,u+d]
            -s[i-1,j+d,u+d]-s[i+d,j-1,u+d]-s[i+d,j+d,u-1]
            +s[i-1,j-1,u+d]+s[i-1,j+d,u-1]+s[i+d,j-1,u-1]
            -s[i-1,j-1,u-1]>=k
             then
               begin
                 can:=true;
                 x:=i;
                 y:=j;
                 z:=u;
                 exit;
               end;
       can:=false;
     end;
function less(x,y:rgb):boolean;
  begin
    less:=(x.r<y.r)or((x.r=y.r)and(x.g<y.g))or((x.r=y.r)and(x.g=y.g)and(x.b<y.b));
  end;
 procedure sort(l,r: longint);
      var
         i,j: longint;
         x,y:rgb;
      begin
         i:=l;
         j:=r;
         x:=h[l+random(r-l)];
         repeat
           while less(h[i],x) do
            inc(i);
           while less(x,h[j]) do
            dec(j);
           if not(i>j) then
             begin
                y:=h[i];
                h[i]:=h[j];
                h[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;


  begin
    assign(input,'rgb.in');
    reset(input);
    assign(output,'rgb.out');
    rewrite(output);
    fillchar(a,sizeof(a),0);
    fillchar(s,sizeof(s),0);
    read(n,k);
    for i:=1 to n do
      begin
        read(x,y,z);
        inc(a[x,y,z]);
        h[i].r:=x;
        h[i].g:=y;
        h[i].b:=z;
        h[i].num:=i;
      end;

    sort(1,n);
//    for i:=1 to n do
//      Writeln(h[i].r,' ',h[i].g,' ',h[i].b,' ',h[i].num);
    for i:=0 to mx do
      for j:=0 to mx do
        for u:=0 to mx do
          s[i,j,u]:=s[i-1,j,u]+s[i,j-1,u]+s[i,j,u-1]
                   -s[i-1,j-1,u]-s[i-1,j,u-1]-s[i,j-1,u-1]
                   +s[i-1,j-1,u-1]+a[i,j,u];
//    Writeln(s[1,0,1]);
    l:=0;
    r:=255;
    while l+1<r do
      begin
        c:=(l+r)div 2;
        if can(c) then r:=c
        else l:=c;
      end;
    was:=false;
    if can(l) then d:=l
    else if can(r) then d:=r;
    for i:=x to x+d do
      for j:=y to y+d do
        for u:=z to z+d do
          if a[i,j,u]>0 then
            begin
              if k=0 then break;
              l:=1;
              r:=n;
              h[0].r:=i;h[0].g:=j;h[0].b:=u;
              while l+1<r do
                begin
                  c:=(l+r) shr 1;
                  if less(h[c],h[0]) then l:=c
                  else r:=c;
                end;
              while (l<=n)and((h[l].r<>h[0].r)or(h[l].g<>h[0].g)or(h[l].b<>h[0].b)
                   ) do inc(l);
              r:=l;
              for w:=r to r+min(k,a[i,j,u])-1 do
                begin
                  if was then Write(' ');
                  Write(h[w].num);
                  was:=true;
                end;
              k:=k-min(k,a[i,j,u]);
            end;
    close(input);
    close(output);
  end.
