package main

import "fmt"

var h, w int
var s []string

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

	s = make([]string, h)

	for i := 0; i < h; i++ {
		fmt.Scan(&s[i])
	}

	ans := 0
	for si := 0; si < h; si++ {
		for sj := 0; sj < w; sj++ {
			for gi := 0; gi < h; gi++ {
				for gj := 0; gj < w; gj++ {
					if si == gi && sj == gj {
						continue
					}
					c := rec(si, sj, gi, gj, s)
					if c == 999999999 {
						continue
					}
					// fmt.Println(si, sj, gi, gj, c)
					if ans < c {
						ans = c
					}
				}
			}
		}
	}
	fmt.Println(ans)
}

func rec(si, sj, gi, gj int, s []string) int {
	m := [20][20]int{}

	for i := 0; i < 20; i++ {
		for j := 0; j < 20; j++ {
			m[i][j] = -1
		}
	}

	cnt := 999999999
	var dfs func(c, i, j int)
	dfs = func(c, i, j int) {
		if i == gi && j == gj {
			if c < cnt {
				cnt = c
			}
			return
		}

		if s[i][j] != '.' || m[i][j] != -1 {
			return
		}
		m[i][j] = c

		dd := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}
		for _, d := range dd {
			ni, nj := i+d[0], j+d[1]
			if 0 <= ni && ni < h && 0 <= nj && nj < w {
				dfs(c+1, ni, nj)
			}
		}

		return
	}

	dfs(0, si, sj)

	return cnt
}
