{$APPTYPE CONSOLE}

type TR = record c, p, t, r: Integer end;
var
  f: TextFile;
  teams: array of Integer;
  runs: array of TR;
  r1: TR;
  times, solved: array of Integer;
  totals: array [1..20, 1..1000] of Integer;
  i, j, nruns, nteams, tmp, m, tj, tm: Integer;
begin
//  AssignFile(f, 'input.txt'); Reset(f);
  Read(nteams, nruns);
  SetLength(runs, nruns + 1);
  SetLength(teams, nteams + 1);
  for i := 1 to nruns do with runs[i] do 
    Read(c, p, t, r);
//  CloseFile(f);
  for i := 1 to nruns - 1 do begin
    m := i;
    for j := i + 1 to nruns do
      if runs[j].t < runs[m].t then m := j;
    if m > i then begin
      r1 := runs[i];
      runs[i] := runs[m];
      runs[m] := r1;
    end;
  end;
  SetLength(times, nteams + 1);
  for i := 1 to nteams do times[i] := 0;
  SetLength(solved, nteams + 1);
  for i := 1 to nteams do solved[i] := 0;
  for i := 1 to nruns do with runs[i] do begin
    if r = 0 then begin
      if totals[p, c] <= 0 then Dec(totals[p, c]);
    end else if totals[p, c] <= 0 then begin
      Inc(solved[c]);
      Inc(times[c], t - totals[p, c] * 20 * 60);
      totals[p, c] := 1; 
    end;
  end;
  //for i := 1 to nteams do Write(times[i], ' ');
  for i := 1 to nteams do teams[i] := i;
  for i := 1 to nteams - 1 do begin
    m := i;
    for j := i + 1 to nteams do begin
      tj := teams[j]; tm := teams[m];
      if (solved[tj] > solved[tm])
        or (solved[tj] = solved[tm]) and (times[tj] < times[tm])
        or (solved[tj] = solved[tm]) and (times[tj] = times[tm]) and (tj < tm)
      then m := j;
    end;
    if m > i then begin
      tmp := teams[i];
      teams[i] := teams[m];
      teams[m] := tmp;
    end;
  end;
//  AssignFile(f, 'output.txt'); Rewrite(f);
  for i := 1 to nteams do begin
    //Writeln(teams[i], ' ', solved[teams[i]], ' ', times[teams[i]]);
    if i > 1 then Write(' ');
    Write(teams[i]);
  end;

//  CloseFile(f);
end.
