import java.io.PrintWriter
import java.lang.*
val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()
data class Position(val h: Int, val w: Int, val cost: Int)
fun main(args: Array<String>) {
    val (h, w) = readListOfInt()
    val orgMaze = mutableListOf<MutableList<Char>>()
    val guard = (0 until w+2).map { '#' }.toMutableList()
    orgMaze.add(guard)
    for(i in 0 until h) {
        val m = read()
        orgMaze.add(("#" + m + "#").toMutableList())
    }
    orgMaze.add(guard)
    val directions = listOf(Pair(0, -1), Pair(0, 1), Pair(-1, 0), Pair(1, 0)) // left, right, down, top
    var ans = 0
    for(i in 1 until h+1) {
        for(j in 1 until w+1) {
            val que = Queue<Position>()
            if(orgMaze[i][j] == '.') {
                val maze = orgMaze.map { it.toMutableList() }
                que.push(Position(i, j, 0))
                var cost = 0
                while(!que.isEmpty()) {
                    val cpos = que.top()
                    maze[cpos.h][cpos.w] = '#'
                    que.pop()
                    directions.forEach { direction ->
                        val nh = direction.first + cpos.h
                        val nw = direction.second + cpos.w
                        cost = Math.max(cost, cpos.cost)
                        if(maze[nh][nw] == '.') {
                            que.push(Position(nh, nw, cpos.cost + 1))
                            maze[nh][nw] = '#'
                        }
                    }
                }
                ans = Math.max(ans, cost)
            }
        }
    }
    println(ans)
    pw.flush()
}
fun read() = readLine()!!
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)
fun println(value : Any) { pw.println(value) }
class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}
