package main

import (
	"fmt"
)

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++ {
			distance := searchMax(Point{i, j}, maze, h, w)
			if distance > maxDistance {
				maxDistance = distance
			}
		}
	}

	fmt.Println(maxDistance)
}

func searchMax(start Point, done [20][20]bool, h, w int) int {
	maxDistance := 0
	heads := []Point{start}
	for {
		var newHeads []Point
		for _, head := range heads {
			for _, xy := range [4][2]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}} {
				i := head.I + xy[0]
				j := head.J + xy[1]
				if i < 0 || i >= h || j < 0 || j >= w {
					continue
				}
				if done[i][j] == true {
					continue
				}
				done[i][j] = true
				newHeads = append(newHeads, Point{i, j})
			}
		}
		if len(newHeads) != 0 {
			maxDistance++
		} else {
			break
		}
		heads = newHeads
	}
	return maxDistance
}
