Problem:
Score : 400 points

Problem Statement

Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.

The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is #, and a "road" square if S_{ij} is ..

From a road square, you can move to a horizontally or vertically adjacent road square.

You cannot move out of the maze, move to a wall square, or move diagonally.

Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.

Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.

In this situation, find the maximum possible number of moves Aoki has to make.

Constraints

1 \leq H,W \leq 20

S_{ij} is . or #.

S contains at least two occurrences of ..

Any road square can be reached from any road square in zero or more moves.

Input

Input is given from Standard Input in the following format:

H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW}

Output

Print the maximum possible number of moves Aoki has to make.

Sample Input 1

3 3
...
...
...

Sample Output 1

4

If Takahashi chooses the top-left square as the starting square and the bottom-right square as the goal square, Aoki has to make four moves.

Sample Input 2

3 5
...#.
.#.#.
.#...

Sample Output 2

10

If Takahashi chooses the bottom-left square as the starting square and the top-right square as the goal square, Aoki has to make ten moves.

Solution in Go (1.14.1) (judge verdict: Wrong Answer)

// Command quickstart generates an audio file with the content "Hello, World!".
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func scanInt() int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return a
}

func scanFloat() float64 {
	sc.Scan()
	a, _ := strconv.ParseFloat(sc.Text(), 64)
	return a
}

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

func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

var (
	h int
	w int
	g [][]string
)

type Pair struct {
	x int
	y int
}

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

func bfs(sy int, sx int) int {
	q := []Pair{{y:sy, x:sx}}
	dist := make([][]int, h)
	for i:=0; i<h; i++ {
		dist[i] = make([]int, w)
	}
	for i:=0; i<h; i++ {
		for j:=0; j<w; j++ {
			dist[i][j] = inf
		}
	}
	dist[sy][sx] = 0
	for len(q) > 0 {
		u := q[0]
		q = q[1:]
		for i:=0; i<4; i++ {
			nx := u.x + dx[i]
			ny := u.y + dy[i]
			if nx < 0 || nx >= w || ny < 0 || ny >= h {
				continue
			}
			if g[ny][nx] == "#" {
				continue
			}
			if dist[ny][nx] > dist[u.y][u.x] + 1 {
				dist[ny][nx] = dist[u.y][u.x] + 1
				q = append(q, Pair{y:ny, x:nx})
			}
		}
	}
	res := 0
	for i:=0; i<h; i++ {
		for j:=0; j<w; j++ {
			if dist[i][j] == inf {
				continue
			}
			res = max(res, dist[i][j])
		}
	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	h = scanInt()
	w = scanInt()
	g = make([][]string, h)
	for i:=0; i<h; i++ {
		g[i] = make([]string, w)
	}
	for i:=0; i<h; i++ {
		str := scanText()
		s := strings.Split(str, "")
		for j:=0; j<w; j++ {
			g[i][j] = s[j]
		}
	}

	res := 0
	for i:=0; i<h; i++ {
		for j:=0; j<w; j++ {
			res = max(res, bfs(i, j))
		}
	}
	fmt.Println(res)
}