import std.stdio, std.string, std.conv;
import std.algorithm, std.array, std.range;
auto solve(string S_) {
    auto NM=S_.split.map!(to!int)();
    immutable N=NM[0], M=NM[1];
    auto A=new int[][N];
    foreach(ref a;A) a=readln.split.map!(to!int).array();
    auto c=new int[M+1];
    foreach(a;A) ++c[a[0]];
    int m=N; bool[int] s;
    foreach(r;0..M) {
        int k=-1,j=-1;
        foreach(int i,v;c) if(k<v) k=v,j=i;
        m=min(m,k);
        if(r+1>=M) break;
        s[j]=true;
        foreach(ref a;A) while(a[0] in s) a.popFront, --c[j], ++c[a[0]];
    }
    return m;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }