import java.lang.Math
import kotlin.comparisons.*

val MOD: Int = 1000000000 + 7
val MODL: Long = MOD.toLong()

var maze: Array<Array<Boolean>> = arrayOf<Array<Boolean>>()

fun main(args: Array<String>)
{
    val (h, w) = read().split().toInt()
    // val minStep = IntArray(h*w) {-1}
    var outside = arrayOf<Boolean>()
    for (i in 1..w+2) {
        outside += false
    }
    maze += outside // 迷路の外(上側)
    for (i in 0 until h) {
        val s = read().toCharArray()
        var row = arrayOf<Boolean>()
        row += false // 迷路の外(左側)
        for (c in s) {
            row += c == '.'
        }
        row += false // 迷路の外(右側)
        maze += row
    }
    maze += outside // 迷路の外(下側)

    var ans = -1
    for (sy in 1..h) {
        for (sx in 1..w) {
            if (!maze[sy][sx]) continue
            for (gy in 1..h) {
                for (gx in 1..w) {
                    if (!maze[gy][gx]) continue
                    ans = Math.max(ans, move(sy, sx, gy, gx, mutableListOf<Pair<Int, Int>>()))
                }
            }
            // minStep[(i-1) * w + (k-1)] = calc(i, k)
        }
    }
    println(ans)
}

fun move(y: Int, x: Int, gy: Int, gx: Int, path: MutableList<Pair<Int, Int>>): Int {
    path.add(Pair<Int, Int>(y, x))
    if (y == gy && x == gx) {
        val len = path.lastIndex
        path.removeAt(len)
        return len
    }

    var minStep = Int.MAX_VALUE
    if (maze[y-1][x] && !path.contains(Pair<Int, Int>(y-1, x))) {
        minStep = Math.min(minStep, move(y-1, x, gy, gx, path))
    }
    if (maze[y+1][x] && !path.contains(Pair<Int, Int>(y+1, x))) {
        minStep = Math.min(minStep, move(y+1, x, gy, gx, path))
    }
    if (maze[y][x-1] && !path.contains(Pair<Int, Int>(y, x-1))) {
        minStep = Math.min(minStep, move(y, x-1, gy, gx, path))
    }
    if (maze[y][x+1] && !path.contains(Pair<Int, Int>(y, x+1))) {
        minStep = Math.min(minStep, move(y, x+1, gy, gx, path))
    }
    path.removeAt(path.lastIndex)
    return minStep
}

fun read(): String = readLine()!!
fun CharSequence.split(): List<String> = this.split(" ")
fun Iterable<String>.toInt(): List<Int> = this.map{it.toInt()}
fun Iterable<String>.toLong(): List<Long> = this.map{it.toLong()}
