package main

import (
	"fmt"
)

var H, W int
var S = [20][20]string{}

func main() {
	fmt.Scanf("%d %d\n", &H, &W)

	for i := 0; i < H; i++ {
		var s string
		fmt.Scanf("%s", &s)
		rs := []rune(s)
		for j := 0; j < W; j++ {
			s := string(rs[j])
			S[i][j] = s
		}
	}
	var max int

	for i := 0; i < H*W; i++ {
		h := i / W
		w := i % W
		start := S[h][w]
		if start == "#" {
			continue
		}
		r := bfs(i)
		for j := i + 1; j < H*W; j++ {
			gh := j / W
			gw := j % W
			goal := S[gh][gw]
			if goal == "#" {
				continue
			}
			if r[j] > max {
				max = r[j]
			}
		}
	}
	fmt.Println(max)
}

func bfs(s int) map[int]int {
	t := map[int]int{}
	queue := []int{s}
	for len(queue) > 0 {
		q := queue[0]
		queue = queue[1:]
		x := q % W
		y := q / W
		if x > 0 {
			nx := x - 1
			if S[y][nx] == "." {
				nq := nx%W + q - x
				if _, e := t[nq]; !e {
					t[nq] = t[q] + 1
					queue = append(queue, nq)
				}

			}
		}
		if x < W {
			nx := x + 1
			if S[y][nx] == "." {
				nq := nx%W + q - x
				if _, e := t[nq]; !e {
					t[nq] = t[q] + 1
					queue = append(queue, nq)
				}
			}
		}
		if y < H {
			ny := y + 1
			if S[ny][x] == "." {
				nq := ny*W + x
				if _, e := t[nq]; !e {
					t[nq] = t[q] + 1
					queue = append(queue, nq)
				}

			}
		}
		if y > 0 {
			ny := y - 1
			if S[ny][x] == "." {
				nq := ny*W + x
				if _, e := t[nq]; !e {
					t[nq] = t[q] + 1

					queue = append(queue, nq)
				}
			}
		}
	}

	return t
}
