package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"math/rand"
	"os"
	"strconv"
	"time"
)

var sc = bufio.NewScanner(os.Stdin)

var m [][]byte
var h, w int

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	start := time.Now()
	rand.Seed(time.Now().UnixNano())
	h = nextInt()
	w = nextInt()
	m = make([][]byte, h)
	for i := 0; i < h; i++ {
		s := nextString()
		m[i] = []byte(s)
	}
	max_distance := -1
	// w_rnd_1 := make([]int, w)
	// w_rnd_2 := make([]int, w)
	// h_rnd_1 := make([]int, h)
	// h_rnd_2 := make([]int, h)
	// for i := 0; i < w; i++ {
	// 	w_rnd_1[i] = i
	// 	w_rnd_2[i] = i
	// }
	// for i := 0; i < h; i++ {
	// 	h_rnd_1[i] = i
	// 	h_rnd_2[i] = i
	// }
	// w_rnd_1 = shaffle(w_rnd_1)
	// w_rnd_2 = shaffle(w_rnd_2)
	// h_rnd_1 = shaffle(h_rnd_1)
	// h_rnd_2 = shaffle(h_rnd_2)
	for x1 := 0; x1 < w; x1++ {
		// x1 := w_rnd_1[xi1]
		for y1 := 0; y1 < h; y1++ {
			// y1 := h_rnd_1[yi1]
			if m[y1][x1] == '#' {
				continue
			}
			for x2 := w - 1; x2 >= 0; x2-- {
				// x2 := w_rnd_2[xi2]
				for y2 := h - 1; y2 >= 0; y2-- {
					// y2 := h_rnd_2[yi2]
					if x1 == x2 && y1 == y2 {
						continue
					}
					if m[y2][x2] == '#' {
						continue
					}
					max_distance = max(max_distance, distance(x1, y1, x2, y2))
					if max_distance == h*w {
						fmt.Println(h * w)
						return
					}
					now := time.Now()
					if now.Sub(start) > 1900*time.Millisecond {
						fmt.Println(max_distance)
						return
					}
				}
			}
		}
	}
	fmt.Println(max_distance)
}

func shaffle(a []int) []int {
	for i := 0; i < len(a); i++ {
		j := int(xorshift()) % len(a)
		a[i], a[j] = a[j], a[i]
	}
	return a
}

var (
	x  uint32 = 123456789
	y  uint32 = 362436069
	z  uint32 = 521288629
	w_ uint32 = 88675123
	t  uint32
)

func xorshift() uint32 {
	t = x ^ (x << 11)
	x = y
	y = z
	z = w_
	w_ = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8))
	return w_
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}

func distance(x1, y1, x2, y2 int) int {
	var dist [21][21]int
	q := make([]pair, 0)
	q = append(q, pair{x1, y1})
	dist[y1][x1] = 1
	index := 0
	// cnt := 0
	for index < len(q) {
		// cnt++
		// if cnt > 240 {
		// break
		// }
		now := q[index]
		for d := 0; d < 4; d++ {
			nx := now.a + dx[d]
			ny := now.b + dy[d]
			if nx >= 0 && nx < w && ny >= 0 && ny < h {
				if m[ny][nx] == '.' {
					if dist[ny][nx] == 0 || dist[ny][nx] > dist[now.b][now.a]+1 {
						q = append(q, pair{nx, ny})
						dist[ny][nx] = dist[now.b][now.a] + 1
						if nx == x2 && ny == y2 {
							break
						}
					}
				}
			}
		}
		index++
	}
	return dist[y2][x2] - 1
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 10880