package main

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

func StrStdin() string {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	return strings.TrimSpace(scanner.Text())
}

func Int64Stdin() int64 {
	stringInput := StrStdin()
	num, _ := strconv.ParseInt(strings.TrimSpace(stringInput), 10, 64)
	return num
}

func SplitWithoutEmpty(stringTargeted string, delim string) []string {
	stringSplited := strings.Split(stringTargeted, delim)
	strs := []string{}

	for _, str := range stringSplited {
		if str != "" {
			strs = append(strs, str)
		}
	}
	return strs
}

func SliceStrStdin(delim string) []string {
	stringInput := StrStdin()
	return SplitWithoutEmpty(stringInput, delim)
}

func SliceInt64Stdin() []int64 {
	stringSplited := SliceStrStdin(" ")

	uint64Slice := []int64{}

	for ni := range stringSplited {
		num, _ := strconv.ParseInt(stringSplited[ni], 10, 64)
		uint64Slice = append(uint64Slice, num)
	}

	return uint64Slice
}

type Maze struct {
	maze []string
}

var (
	H, W int64
	m    Maze
	dist [30][30]int64
	dy   = [4]int64{0, 1, 0, -1}
	dx   = [4]int64{1, 0, -1, 0}
)

type Point struct {
	y int64
	x int64
}

func BFS(y, x int64) int64 {

	que := []Point{}
	que = append(que, Point{y: y, x: x})
	ans := int64(0)

	for hy := 0; int64(hy) < H; hy++ {
		for wx := 0; int64(wx) < W; wx++ {
			dist[hy][wx] = 0
		}
	}

	for len(que) > 0 {

		q := que[0]
		que = que[1:]
		for dir := 0; dir < len(dy); dir++ {
			ny := q.y + dy[dir]
			nx := q.x + dx[dir]


			if (0 <= ny && int64(ny) < H) && (0 <= nx && int64(nx) < W) {
				if m.maze[ny][nx] != '.' {
					continue
				}
				if dist[ny][nx] > 0 {
					continue
				}
				que = append(que, Point{y: ny, x: nx})
				dist[ny][nx] = dist[q.y][q.x] + 1
				ans = int64(math.Max(float64(ans), float64(dist[ny][nx])))
			}
		}
	}

	return ans
}

func Solve() {
	HW := SliceInt64Stdin()
	H, W = HW[0], HW[1]

	for hy := 0; int64(hy) < H; hy++ {
		m.maze = append(m.maze, StrStdin())
	}

	var res int64
	res = 0
	for hy := 0; int64(hy) < H; hy++ {
		for wx := 0; int64(wx) < W; wx++ {
			if m.maze[hy][wx] == '.' {
				res = int64(math.Max(float64(res), float64(BFS(int64(hy), int64(wx)))))
			}
		}
	}

	fmt.Println(res)
}

func main() {
	Solve()
}