Insider's Information

Follow the given removal order, then insert each university at the front or back to satisfy at least half the betweenness triples.

Medium5SimulationGreedyTopological sortHeapNo attempts yetTime limit2sMemory limit256 MB

Problem

Ian works for a rating agency that publishes a rating of the best universities. Irene is a journalist who plans to write a scandalous article about the upcoming rating.

Irene used a few social engineering tricks (let us skip the details) and got some insider's information from Ian.

She received several triples (ai,bi,ci)(a_i, b_i, c_i) of university numbers. Each triple means that in the upcoming rating university bib_i stands between universities aia_i and cic_i: either aia_i comes before bib_i and bib_i comes before cic_i, or the other way round. Every triple Ian told her agrees with the actual rating, and the actual rating satisfies all of them.

To start the first draft of the article, Irene needs a proposal that is at least close to the actual rating. Find a proposal that satisfies at least half of the triples. Many proposals do that, so print the one built by the procedure given in the output section.

Input

The first line contains two integers nn and mm, the number of rated universities and the number of triples Ian gave to Irene (3n1000003 \le n \le 100000; 1m1000001 \le m \le 100000).

Each of the next mm lines contains three distinct integers aia_i, bib_i and cic_i, the universities of one triple (1ai,bi,cin1 \le a_i, b_i, c_i \le n). At least one rating satisfies all mm triples.

Output

Print the university numbers from the first place to the last place in one line, separated by single spaces.

Several proposals satisfy at least half of the triples, so print exactly the one that the following procedure builds.

Stage 1, the removal order. Every triple starts alive. In a triple (a,b,c)(a, b, c) call bb the middle university and call aa and cc the end universities. A university is free when it is the middle university of no living triple. Repeat nn times: among the universities that are still present, remove the free one with the smallest number. The universities get removal ranks 11 to nn in the order in which they are removed. When a university is removed, every living triple that has it as an end university dies. The guarantee on the input makes a free university exist at every step.

Stage 2, the placement. Place the universities in the reverse order of removal, from rank nn down to rank 11. The university of rank nn alone is the starting sequence. The university uu of rank ii goes either to the front or to the back of the sequence built so far. Look only at the triples whose three universities all have removal rank at least ii. In such a triple uu is an end university. Write ww for its middle university and vv for its other end university. Putting uu at the front satisfies the triple when ww stands before vv in the current sequence, and putting uu at the back satisfies it when vv stands before ww. Count the triples that each of the two options satisfies and take the option with the larger count. When the two counts are equal, put uu at the front.

The proposal built this way always satisfies at least m/2m/2 triples.

Hint

The university that comes first in the actual rating is the middle university of no triple. The same holds inside the set of universities that are still present, so stage 1 never gets stuck.

In stage 2 a triple is judged once, at the step that places the university with the smallest removal rank among its three, and that university is an end university of the triple. One of the two options, front or back, satisfies the triple, so the option with the larger count satisfies at least half of the triples judged at that step. Adding up all steps gives at least m/2m/2.