// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;

void main() {
    int n, m;
    int[][] a;

    scan(n, m);
    a = new int[][](n, m);
    iota(n).each!(i => a[i][] = readln.split.to!(int[]));
    iota(n).each!(i => a[i][] -= 1);

    int top = n, btm = 0;

    bool check(int k) {
        int[] cnt = new int[](m);
        bool[] ok = new bool[](m);
        ok[] = true;
        int oknum = m;

        while (oknum > 0) {
            cnt[] = 0;

            foreach (i ; 0 .. n) {
                foreach (j ; 0 .. m) {
                    if (ok[a[i][j]]) {
                        cnt[a[i][j]]++;
                        break;
                    }
                }
            }

            bool flag = true;

            foreach (j ; 0 .. m) {
                if (cnt[j] > k) {
                    ok[j] = false;
                    oknum--;
                    flag = false;
                }
            }

            if (flag) return true;
        }

        return false;
    }

    while (top - btm > 1) {
        int mid = (top + btm) / 2;
        (check(mid) ? top : btm) = mid;
    }

    writeln(top);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}