// Command quickstart generates an audio file with the content "Hello, World!".
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func scanInt() int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return a
}

func scanFloat() float64 {
	sc.Scan()
	a, _ := strconv.ParseFloat(sc.Text(), 64)
	return a
}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

var (
	h int
	w int
	g [][]string
)

type Pair struct {
	x int
	y int
}

var inf int = 1000000007
var dx [4]int = [4]int{1, 0, -1, 0}
var dy [4]int = [4]int{0, 1, 0, -1}

func bfs(sy int, sx int) int {
	q := []Pair{{y:sy, x:sx}}
	dist := make([][]int, h)
	for i:=0; i<h; i++ {
		dist[i] = make([]int, w)
	}
	for i:=0; i<h; i++ {
		for j:=0; j<w; j++ {
			dist[i][j] = inf
		}
	}
	dist[sy][sx] = 0
	for len(q) > 0 {
		u := q[0]
		q = q[1:]
		for i:=0; i<4; i++ {
			nx := u.x + dx[i]
			ny := u.y + dy[i]
			if nx < 0 || nx >= w || ny < 0 || ny >= h {
				continue
			}
			if g[ny][nx] == "#" {
				continue
			}
			if dist[ny][nx] > dist[u.y][u.x] + 1 {
				dist[ny][nx] = dist[u.y][u.x] + 1
				q = append(q, Pair{y:ny, x:nx})
			}
		}
	}
	res := 0
	for i:=0; i<h; i++ {
		for j:=0; j<w; j++ {
			if dist[i][j] == inf {
				continue
			}
			res = max(res, dist[i][j])
		}
	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	h = scanInt()
	w = scanInt()
	g = make([][]string, h)
	for i:=0; i<h; i++ {
		g[i] = make([]string, w)
	}
	for i:=0; i<h; i++ {
		str := scanText()
		s := strings.Split(str, "")
		for j:=0; j<w; j++ {
			g[i][j] = s[j]
		}
	}

	res := 0
	for i:=0; i<h; i++ {
		for j:=0; j<w; j++ {
			res = max(res, bfs(i, j))
		}
	}
	fmt.Println(res)
}
