unittest
{
	assert( [ "4 5", "5 1 3 4 2", "2 5 3 1 4", "2 3 1 4 5", "2 5 4 3 1" ].parse.expand.solve == 2 );
	assert( [ "3 3", "2 1 3", "2 1 3", "2 1 3" ].parse.expand.solve == 3 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto ass = new long[][]( nm[ 0 ], nm[ 1 ] );
	foreach( ref as; ass )
	{
		input.popFront;
		as = input.front.split.to!( long[] );
		as[] -= 1;
	}
	return tuple( nm[ 1 ], ass );
}

auto solve( long m, long[][] ass )
{
	auto ans = long.max;
	auto bs = new bool[ m ];
	LOOP: while( true )
	{
		// 最大参加人数を計算
		long cm = 0L;
		long[ long ] cs;
		foreach( as; ass )
		{
			while( !as.empty && bs[ as.front ] ) as.popFront;
			if( as.empty ) break LOOP;
			cs[ as.front ]++;
			cm = max( cm, cs[ as.front ] );
		}
		ans = min( ans, cm );
		
		// 参加人数が最大のスポーツを中止にする
		foreach( k, c; cs )
		{
			bs[ k ] = ( c == cm );
		}
	}
	return ans;
}
