fun main(args:Array<String>?): Unit {
    while(true){
        val m = readLine()!!.trim().toInt()
        val n = readLine()!!.trim().toInt()
        if (m == 0 && n == 0) return
        val state = Array(n){ readLine()!!.trim().split(' ').map{it == "0"}.toBooleanArray() }
        println(
                solve(state)
        )
    }
}

fun solve(state: Array<BooleanArray>): Int {
    fun sub(x: Int, y: Int): Int {
        return if (y !in state.indices || x !in state[y].indices || state[y][x]) 0
        else {
            state[y][x] = true
            val max = listOf(sub(x + 1, y), sub(x - 1, y), sub(x, y + 1), sub(x, y - 1)).max()!!
            state[y][x] = false
            return max + 1
        }
    }
    return state.indices.mapNotNull{y -> state[y].indices.filterNot{x -> state[y][x]}.map{x -> sub(x, y)}.max()}.max() ?: 0
}
