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 C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var INF = -1;
            var r = ReadSplit();
            var h = r[0].ToInt();
            var w = r[1].ToInt();
            var table = new string[h][];
            for (int i = 0; i < h; i++)
            {
                var r2 = Read();
                table[i] = new string[w];
                for (int j = 0; j < r2.Length; j++)
                {
                    table[i][j] = r2[j].ToString();
                }
            }

            var ans = 0;
            for (int k = 0; k < h; k++)
            {
                for (int l = 0; l < w; l++)
                {
                    
                    var q = new List<Tuple<int, int>>();
                    var dist = new int[h][];

                    for (int i = 0; i < h; i++)
                    {
                        dist[i] = new int[w];
                        for (int j = 0; j < w; j++)
                        {
                            dist[i][j] = INF;
                        }
                    }

                    var Add = new Action<int, int, int>((y, x, d) =>
                    {
                        if (table[y][x] == "#") return;
                        if (dist[y][x] != INF) return;
                        q.Add(new Tuple<int, int>(y, x));
                        dist[y][x] = d;
                        if (ans < d)
                        {
                            ans = d;
                        }
                    });

                    q.Add(new Tuple<int, int>(k, l));
                    dist[k][l] = 0;

                    while (q.Any())
                    {
                        var v = q[0]; q.RemoveAt(0);
                        var x = v.Item2;
                        var y = v.Item1;
                        var d = dist[y][x];
                        if (x + 1 < w) Add(y, x + 1, d + 1);
                        if (x - 1 >= 0) Add(y, x - 1, d + 1);
                        if (y + 1 < h) Add(y + 1, x, d + 1);
                        if (y - 1 >= 0) Add(y - 1, x, d + 1);
                    }
                }
            }
            WriteRead(ans);
        }

        public class ACWA
        {
            public int AC { get; set; }
            public int WA { get; set; }
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }
    }
}


public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }
}