package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	h = nextInt()
	w = nextInt()
	m = make([][]byte, h)
	for i := 0; i < h; i++ {
		s := nextString()
		m[i] = []byte(s)
	}
	max_distance := -1
	for x1 := 0; x1 < w; x1++ {
		for y1 := 0; y1 < h; y1++ {
			if m[y1][x1] == '#' {
				continue
			}
			for x2 := w - 1; x2 >= 0; x2-- {
				for y2 := h - 1; y2 >= 0; y2-- {
					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
					}
				}
			}
		}
	}
	fmt.Println(max_distance)
}

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 > 50 {
			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
}
