package main

import (
	"fmt"
)

var h, w int
var ss [][]byte

func main() {
	fmt.Scan(&h, &w)

	ss = make([][]byte, h)
	for i := range ss {
		fmt.Scan(&ss[i])
	}

	cs := calc(0, 0)
	m := -1
	var sy, sx int
	for i := range cs {
		for j := range cs[i] {
			if cs[i][j] > m {
				m = cs[i][j]
				sy, sx = i, j
			}
		}
	}

	ds := calc(sy, sx)
	m2 := -1
	for i := range ds {
		for j := range ds[i] {
			if ds[i][j] > m2 {
				m2 = ds[i][j]
			}
		}
	}

	fmt.Println(m2)
}

func calc(y, x int) [][]int {
	cnts := make([][]int, h)
	for i := range cnts {
		cnts[i] = make([]int, w)
		for j := range cnts[i] {
			cnts[i][j] = -1
		}
	}

	qs := make([][]int, 0)
	qs = append(qs, []int{y, x})
	cnts[y][x] = 0
	for len(qs) > 0 {
		q := qs[0]
		cy, cx := q[0], q[1]
		for _, d := range [][]int{{1, 0}, {-1, 0}, {0, 1}, {0, -1}} {
			ny, nx := cy+d[0], cx+d[1]
			if ny >= 0 && ny < h && nx >= 0 && nx < w && ss[ny][nx] == '.' && cnts[ny][nx] == -1 {
				cnts[ny][nx] = cnts[cy][cx] + 1
				qs = append(qs, []int{ny, nx})
			}
		}
		qs = qs[1:]
	}
	return cnts
}
