package main

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

type point struct {
	r, c int
}

func main() {
	scanner := makeScanner(8192)
	hw := eGetInts(scanner)
	h, w := hw[0], hw[1]
	maze := make([][]string, h+2)
	for i := 0; i < len(maze); i++ {
		maze[i] = make([]string, w+2)
		for j := 0; j < w+2; j++ {
			maze[i][j] = "#"
		}
	}
	for i := 0; i < h; i++ {
		line := eGetChars(scanner)
		for j := 0; j < w; j++ {
			for k := 0; k < len(line); k++ {
				maze[i+1][1+k] = line[k]
			}
		}
	}

	bfs := func(start, goal int) int {
		p := point{start/w + 1, start%w + 1}
		g := point{goal/w + 1, goal%w + 1}
		lengths := make(map[point]int)
		q := []point{p}
		lengths[p] = 0
		for len(q) > 0 {
			// 先頭を出す
			p, q = q[0], q[1:]
			// fmt.Println(p)
			if p == g {
				break
			}
			nexts := []point{
				point{p.r, p.c + 1}, // 東
				point{p.r, p.c - 1}, // 西
				point{p.r + 1, p.c}, // 南
				point{p.r - 1, p.c}} // 北
			for _, next := range nexts {
				if _, ok := lengths[next]; !ok && maze[next.r][next.c] != "#" {
					q = append(q, next)
					lengths[next] = lengths[p] + 1
				}
			}
		}
		return lengths[p]
	}
	// fmt.Println(bfs(10, 4))

	max := 0
	for start := 0; start < h*w; start++ {
		for goal := 0; goal < h*w; goal++ {
			length := bfs(start, goal)
			if max < length {
				max = length
			}
		}
	}

	// for i := 0; i < len(maze); i++ {
	// 	fmt.Println(maze[i])
	// }
	fmt.Println(max)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeCharScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanRunes)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func pow(a, n int) int {
	return int(math.Pow(float64(a), float64(n)))
}
func countBitOfOn(i, numbits int) int {
	count := 0
	var bit uint64
	for bit = 0; bit < uint64(numbits); bit++ {
		t := 1 << bit
		if i&t > 0 {
			count++
		}
	}
	return count
}
