import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val m = cin.nextInt()

    val a = Array<Array<Int>>(n, { Array<Int>(m, { cin.nextInt()-1 }) })

    val count = Array<MutableList<Int>>(m, { mutableListOf() })

    val point = Array<Int>(n, { 0 })
    val valid = Array<Boolean>(m, { true })

    for (i in 0..n-1) {
        count[a[i][0]].add(i)
    }

    var min_of_max = -1
    var valid_num = m

    while (valid_num > 1) {
        var count_max = count[0].size
        var count_max_idx = 0
        for (i in 0..m-1) {
            if (count[i].size > count_max) {
                count_max = count[i].size
                count_max_idx = i
            }
        }

        if (0 > min_of_max || min_of_max > count_max) {
            min_of_max = count_max
        }

        valid[count_max_idx] = false
        valid_num -= 1

        for (person in count[count_max_idx]) {
            while (!valid[a[person][point[person]]]) {
                point[person] += 1
            }
            count[a[person][point[person]]].add(person)
        }

        count[count_max_idx] = mutableListOf()
    }

    if (m == 1) {
        min_of_max = n
    }
    
    println(min_of_max)
}