package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func floatSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	h, w := iScan(), iScan()
	s := SScan(h)
	g := make([][]int, h*w)
	for i, _ := range g {
		g[i] = make([]int, h*w)
		for j, _ := range g[i] {
			g[i][j] = mod
		}
	}
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if string(s[i][j]) == "." {
				if i+1 < h {
					if string(s[i+1][j]) != "#" {
						g[i*w+j][(i+1)*w+j] = 1
					}
				}
				if i > 0 {
					if string(s[i-1][j]) != "#" {
						g[i*w+j][(i-1)*w+j] = 1
					}
				}
				if j+1 < w {
					if string(s[i][j+1]) != "#" {
						g[i*w+j][i*w+j+1] = 1
					}
				}
				if j > 0 {
					if string(s[i][j-1]) != "#" {
						g[i*w+j][i*w+j-1] = 1
					}
				}
			}
		}
	}
	for k := 0; k < h*w; k++ {
		for i := 0; i < h*w; i++ {
			for j := 0; j < h*w; j++ {
				g[i][j] = smaller(g[i][j], g[i][k]+g[j][k])
			}
		}
	}
	ans := 0
	for i, _ := range g {
		for j, _ := range g[i] {
			if g[i][j] < mod {
				ans = larger(ans, g[i][j])
			}
		}
	}
	fmt.Println(ans)
}
