{$APPTYPE CONSOLE}

var f: text;
type d = record
       c : Integer; {1..1000}
       p : Integer; {1..20}
       t : Integer; {1..36000}
       r : Integer;
     end;

var
  data: array[1..1001] of d;
  C, N: Integer;
  i, j: Integer;
  resolved: array[1..1001, 1..20] of Integer;
  consumed_time: array[1..1001] of Integer;
  problems_solved: array[1..1001] of Integer;
  rank: array[1..1001] of Integer;
  b: boolean;
begin
//  assign(f, 'input.txt');
//  reset(f);
  read(C, N);
  for i := 1 to C do begin
    for j := 1 to 20 do
      resolved[i,j] := 656350;
    consumed_time[i] := 0;
    problems_solved[i] := 0;
    rank[i] := i;
  end;
  for i := 1 to N do begin
    read(data[i].c, data[i].p, data[i].t, data[i].r);
    if data[i].r <> 0 then
      if data[i].t < resolved[data[i].c, data[i].p] then
        resolved[data[i].c, data[i].p] := data[i].t;
  end;
//  close(f);

  for i := 1 to N do
    if resolved[data[i].c, data[i].p] < 656350 then begin
      if data[i].t < resolved[data[i].c, data[i].p] then
        inc(consumed_time[data[i].c], 1200)
    end;
  for i := 1 to C do begin
    for j := 1 to 20 do
      if resolved[i, j] < 656350 then begin
        inc(consumed_time[i], resolved[i, j]);
        inc(problems_solved[i]);
      end;
  end;

  repeat
    b := true;
    for i := 1 to C do
      if (problems_solved[rank[i+1]] > problems_solved[rank[i]]) or
        ((problems_solved[rank[i+1]] = problems_solved[rank[i]]) and
        (consumed_time[rank[i+1]] < consumed_time[rank[i]]))
      then begin
        j := rank[i+1];
        rank[i+1] := rank[i];
        rank[i] := j;
        b := false;
      end;
  until b;

//  assign(f, 'output.txt');
//  rewrite(f);
  for i := 1 to C do begin
    if i <> 1 then write(' ');
    write(rank[i]);
  end;
//  close(f);

  {for i := 1 to C do begin
    writeln('Team ', rank[i], ' Solved = ', problems_solved[rank[i]], ' Consumed = ', consumed_time[rank[i]]);
    write(' ');
    for j := 1 to C do
      if resolved[i,j] < 656350 then write(' ', resolved[i,j]) else write(' N');
    writeln;
  end;}
end.
