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 sy := 0; sy < h; sy++ {
		for sx := 0; sx < w; sx++ {
			for gy := 0; gy < h; gy++ {
				for gx := 0; gx < w; gx++ {
					c := bfs(sy, sx, gy, gx)
					if ans < c {
						ans = c
					}
				}
			}
		}
	}
	fmt.Println(ans)
}

func bfs(sy, sx, gy, gx int) int {
	ps := make([][]int, h)
	for i := 0; i < h; i++ {
		ps[i] = make([]int, w)
		for j := 0; j < w; j++ {
			ps[i][j] = -1
		}
	}
	ps[sy][sx] = 0

	q := make([][]int, 0)
	q = append(q, []int{sy, sx})
	for len(q) > 0 {
		y, x := q[0][0], q[0][1]
		q = q[1:]
		if y == gy && x == gx {
			break
		}

		dd := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}
		for _, d := range dd {
			ny, nx := y+d[0], x+d[1]
			if 0 <= ny && ny < h && 0 <= nx && nx < w {
				if s[ny][nx] == '.' && ps[ny][nx] == -1 {
					ps[ny][nx] = ps[y][x] + 1
					q = append(q, []int{ny, nx})
				}
			}
		}
	}

	return ps[gy][gx]
}
