import java.{util => ju}
object Main {
    var a: Array[ Array[Char] ] = new Array[ Array[Char] ](2)
    var n: Int = 0
    var m: Int = 0

    def go(p: (Int, Int)): List[(Int,Int)] = {
        val (x,y) = p
        return List( (x-1,y), (x+1,y), (x,y-1), (x,y+1) )
    }

    def valid(p: (Int, Int)): Boolean = {
        val (x,y) = p
        return x >= 0 && y >= 0 && x < n && y < m && a(x)(y) == '.'
    }

    def solveQueue(q: List[(Int, Int)], done: List[(Int, Int)], d: Int):Int = {
        if(q.isEmpty)   return 0
        var q1 = q.map(go(_))
        var q2 = List[(Int, Int)]()
        for(x <- q1) q2 = q2 ++ x
        var q3 = q2.distinct.filter(valid)
        var newq = q3.filter(!done.contains(_))
        return Math.max(d, solveQueue(newq, done ++ newq, d+1))
    }

    def solve(xs: Int, ys: Int): Int = {
        return solveQueue(List( (xs, ys) ), List( (xs,ys) ), 0)
    }

    def main(args: Array[String]) = {
        import scala.io.StdIn.readLine
        var Array(nn, mm) = readLine.split(" ").map(_.toInt)
        n = nn; m = mm;
        a = new Array[ Array[Char] ](n)
        for(i <- 0 until n) a(i) = readLine.toCharArray

        var ans = 0
        for(i <- 0 until n)
            for(j <- 0 until m)
                if(a(i)(j) == '.')
                    ans = Math.max(ans, solve(i, j))
        printf("%d\n", ans)
    }
}
