import java.util.*
import kotlin.collections.ArrayDeque

fun main(args: Array<String>){

    var (H, W) = readLine()!!.split(" ").map{it.toInt()}
    var ans = 0
    var S = Array(H){CharArray(W)}
    var dx = arrayOf(1,0,-1,0)
    var dy = arrayOf(0,1,0,-1)

    for(i in S.indices){
        S[i] = readLine()!!.toCharArray()
    }

    for(i in 0 until H){
        for(j in 0 until W){
            var visited = Array(H){Array(W){false}}
            var queue = java.util.ArrayDeque<Data>()

            if(S[i][j] == '.') queue.add(Data(i,j,0))

            while(!queue.isEmpty()){
                var data = queue.poll()
                if(!visited[data.x][data.y]){
                    visited[data.x][data.y] = true
                    ans = Math.max(ans,data.distance)

                    for(k in dx.indices){
                        var x = data.x + dx[k]
                        var y = data.y + dy[k]

                        if(x > -1 && x < H && y > -1 && y< W && !visited[x][y] && S[x][y] == '.'){
                            queue.add(Data(x,y,data.distance+1))
                        }
                    }
                }

            }


        }

    }


    println(ans)

}

class Data(var x:Int,var y:Int,var distance:Int)