import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = rint, m = rint;
	int[][] af = rint(n, m);
	foreach(i; 0 .. n) foreach(j; 0 .. m) af[i][j] -= 1;
	log("n:", n, "m:", m, "af:", af);
	
	int best = n;
	bool[] isAlive = new bool[](m);
	foreach(k; 0 .. m) isAlive[k] = 1;
	log("best:", n, "isAlive:", isAlive);
	while(1){
		int[] count = new int[](m);
		foreach(i; 0 .. n) foreach(j; 0 .. m){
			int k = af[i][j];
			if(isAlive[k]){
				count[k] += 1;
				break;
			}
		}
		log("count:", count);
		
		int temp = 0;
		foreach(k, cnt; count){
			temp = max(temp, cnt);
		}
		best = min(best, temp);
		log("temp:", temp, "best:", best);
		
		foreach(k; 0 .. m){
			if(count[k] >= best) isAlive[k] = 0;
		}
		log("isAlive:", isAlive);
		
		int alivecount;
		foreach(k; 0 .. m) if(isAlive[k]) alivecount += 1;
		log("alivecount:", alivecount);
		if(alivecount == 0) break;
	}
	best.writeln;
}
