package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Point struct {
	h, w int
}

type Queue struct {
	arr []Point
}

func (q *Queue) push(v Point) {
	q.arr = append(q.arr, v)
}

func (q *Queue) pop() Point {
	res := q.arr[0]
	q.arr = q.arr[1:]
	return res
}

func (q *Queue) isEmpty() bool {
	return len(q.arr) == 0
}

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	H, W := sc.nextInt(), sc.nextInt()
	S := make([][]rune, H)
	for i := 0; i < H; i++ {
		S[i] = sc.nextRuneSlice()
	}
	seen := make([][]int, H)
	for i := 0; i < H; i++ {
		seen[i] = make([]int, W)
		for j := 0; j < W; j++ {
			seen[i][j] = -1
		}
	}
	dx := []int{-1, 0, 1, 0}
	dy := []int{0, -1, 0, 1}
	var q Queue
	//var end Point
	var search func(p Point)
	search = func(p Point) {
		//if p.h == end.h && p.w == end.w {
		//	return true
		//}
		for i := 0; i < 4; i++ {
			h, w := p.h+dy[i], p.w+dx[i]
			if h < 0 || H <= h {
				continue
			}
			if w < 0 || W <= w {
				continue
			}
			if seen[h][w] == -1 && S[h][w] != '#' {
				q.push(Point{h, w})
				seen[h][w] = seen[p.h][p.w] + 1
			}
		}
	}
	//end = Point{1, 1}
	ans := 0
	for sh := 0; sh < H; sh++ {
		for sw := 0; sw < W; sw++ {
			for gh := 0; gh < H; gh++ {
				for gw := 0; gw < W; gw++ {
					if S[sh][sw] == '#' || S[gh][gw] == '#' {
						continue
					}
					seen = make([][]int, H)
					for i := 0; i < H; i++ {
						seen[i] = make([]int, W)
						for j := 0; j < W; j++ {
							seen[i][j] = -1
						}
					}
					q.push(Point{sh, sw})
					seen[sh][sw] = 0
					for !q.isEmpty() {
						search(q.pop())
					}
					if seen[gh][gw] != -1 {
						if ans < seen[gh][gw] {
							ans = seen[gh][gw]
						}
					}
				}
			}
		}
	}
	//q.push(Point{2, 0})
	//seen[2][0] = 0

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}
