import java.util.*

fun main(args:Array<String>){
    val (h,w) = readLine()!!.split(" ").map{it.toInt()}
    val s = Array(h){CharArray(w)}
    for(i in 0 until h){
        val t = readLine()!!
        s[i] = t.toCharArray()
    }
    val dx = intArrayOf(0,1,0,-1)
    val dy = intArrayOf(1,0,-1,0)
    val inf = 10000000
    fun calc(y : Int, x : Int) : Int{
        val q = ArrayDeque<Pair<Int,Int>>()
        var dist = Array(h) {IntArray(w){inf} }
        dist[y][x] = 0
        q.push(Pair(y,x))
        while(q.isNotEmpty()){
            val cury = q.first.first
            val curx = q.first.second
            q.removeFirst()
            for(i in 0 .. 3){
                val nexty = cury + dy[i]
                val nextx = curx + dx[i]
                if(nextx >= 0 && nextx < w && nexty >= 0 && nexty < h && dist[nexty][nextx] == inf && s[nexty][nextx] == '.'){
                    dist[nexty][nextx] = dist[cury][curx] + 1
                    q.addLast(Pair(nexty, nextx))
                }
            }
        }
        var ret = 0
        for(i in 0 until h){
            for(j in 0 until w){
                if(dist[i][j] != inf) ret = Math.max(ret, dist[i][j])
            }
        }
        return ret
    }
    var ans = 0
    for(i in 0 until h){
        for(j in 0 until w){
            if(s[i][j] == '.') ans = Math.max(calc(i, j), ans)
        }
    }
    println(ans)
}
