#AGC018B. [AGC018B] Sports Festival

[AGC018B] Sports Festival

Score : 700700 points

Problem Statement

Takahashi is hosting an sports meet. There are NN people who will participate. These people are conveniently numbered 11 through NN. Also, there are MM options of sports for this event. These sports are numbered 11 through MM. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.

Takahashi knows that Person ii's jj-th favorite sport is Sport AijA_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.

Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.

Constraints

  • 1N3001 \leq N \leq 300
  • 1M3001 \leq M \leq 300
  • Ai1A_{i1} , Ai2A_{i2} , ...... , AiMA_{iM} is a permutation of the integers from 11 to MM.

Input

Input is given from Standard Input in the following format:

NN MM

A11A_{11} A12A_{12} ...... A1MA_{1M}

A21A_{21} A22A_{22} ...... A2MA_{2M}

::

AN1A_{N1} AN2A_{N2} ...... ANMA_{NM}

Output

Print the minimum possible number of the participants in the sport with the largest number of participants.

4 5
5 1 3 4 2
2 5 3 1 4
2 3 1 4 5
2 5 4 3 1
2

Assume that Sports 11, 33 and 44 are selected to be played. In this case, Person 11 will participate in Sport 11, Person 22 in Sport 33, Person 33 in Sport 33 and Person 44 in Sport 44. Here, the sport with the largest number of participants is Sport 33, with two participants. There is no way to reduce the number of participants in the sport with the largest number of participants to 11. Therefore, the answer is 22.

3 3
2 1 3
2 1 3
2 1 3
3

Since all the people have the same taste in sports, there will be a sport with three participants, no matter what sports are selected. Therefore, the answer is 33.