package main

import (
	"fmt"
	"math"
)

type Point struct {
	I, J int
}

func main() {
	var h, w int
	fmt.Scanf("%d %d", &h, &w)
	var maze [20][20]bool
	for i := 0; i < h; i++ {
		var line string
		fmt.Scanf("%s", &line)
		for j := 0; j < w; j++ {
			if line[j] == '.' {
				maze[i][j] = false
			} else {
				maze[i][j] = true
			}
		}
	}

	maxDistance := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			for k := i; k < h; k++ {
				for l := 0; l < w; l++ {
					if k == i && l <= j {
						continue
					}
					distance :=  solve(Point{i, j}, Point{k, l}, &maze, h, w)
					if distance > maxDistance {
						maxDistance = distance
					}
				}
			}
		}
	}
	fmt.Println(maxDistance)
}

func solve(start Point, goal Point, maze *[20][20]bool, h, w int) int {
	done := *maze
	done[start.I][start.J] = true
	var distList [4]int
	distList[0] = searchNext(Point{start.I, start.J + 1}, goal, maze, h, w, *maze)
	distList[1] = searchNext(Point{start.I, start.J - 1}, goal, maze, h, w, *maze)
	distList[2] = searchNext(Point{start.I + 1, start.J}, goal, maze, h, w, *maze)
	distList[3] = searchNext(Point{start.I - 1, start.J}, goal, maze, h, w, *maze)
	minDist := math.MaxInt32
	for _, d := range distList {
		if minDist > d {
			minDist = d
		}
	}
	return minDist
}

func searchNext(point Point, goal Point, maze *[20][20]bool, h, w int, done [20][20]bool) int {
	if point.I < 0 || point.J < 0 || point.I >= h || point.J >= w {
		return math.MaxInt32
	}
	if done[point.I][point.J] {
		return math.MaxInt32
	}
	if point.I == goal.I && point.J == goal.J {
		return 1
	}
	done[point.I][point.J] = true
	var distList [4]int
	distList[0] = searchNext(Point{point.I, point.J + 1}, goal, maze, h, w, done)
	distList[1] = searchNext(Point{point.I,point .J - 1}, goal, maze, h, w, done)
	distList[2] = searchNext(Point{point.I + 1, point.J}, goal, maze, h, w, done)
	distList[3] = searchNext(Point{point.I - 1, point.J}, goal, maze, h, w, done)
	minDist := math.MaxInt32
	for _, d := range distList {
		if minDist > d {
			minDist = d
		}
	}
	return minDist + 1
}

