package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	h := getNextInt(scanner)
	w := getNextInt(scanner)
	grid := make([]string, h)

	for i := 0; i < h; i++ {
		grid[i] = getNextString(scanner)
	}

	dd := make([][]int, h)
	for i := 0; i < h; i++ {
		dd[i] = make([]int, w)
	}

	dy := [4]int{
		-1,
		1,
		0,
		0,
	}
	dx := [4]int{
		0,
		0,
		-1,
		1,
	}
	max := 0
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			if grid[y][x] == '#' {
				continue
			}
			for i := 0; i < h; i++ {
				dd[i] = make([]int, w)
				for j := 0; j < w; j++ {
					dd[i][j] = math.MaxInt32
				}
			}

			q := make([]Point, 0)
			q = append(q, Point{
				y: y,
				x: x,
				d: 0,
			})
			for len(q) > 0 {
				p := q[0]
				dd[p.y][p.x] = p.d
				if max < p.d {
					max = p.d
				}
				q = q[1:]
				for i := 0; i < 4; i++ {
					yy := p.y + dy[i]
					xx := p.x + dx[i]
					if yy < 0 {
						continue
					}
					if yy >= h {
						continue
					}
					if xx < 0 {
						continue
					}
					if xx >= w {
						continue
					}
					if grid[yy][xx] == '#' {
						continue
					}
					if dd[yy][xx] < math.MaxInt32 {
						continue
					}
					q = append(q, Point{
						y: yy,
						x: xx,
						d: p.d + 1,
					})
				}
			}
		}
	}

	fmt.Fprintln(writer, max)
}

type Point struct {
	y, x, d int
}
