using System;

public class AtCoderD
{
    static void Main()
    {
        int h;
        int w;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            h = int.Parse(words[0]);
            w = int.Parse(words[1]);
        }

        int[,] map = new int[h, w];

        for (int i = 0; i < h; i++)
        {
            var line = Console.ReadLine();
            for (int j = 0; j < w; j++)
            {
                string str = line.Substring(j, 1);
                if (".".Equals(str))
                {
                    map[i, j] = -1;
                }
                else
                {
                    map[i, j] = -2;
                }
            }
        }

        int answer = 0;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                int[,] newMap = (int[,])map.Clone();
                newMap[i, j] = 0;
                int ans = solve(newMap, h, w);
                if (ans > answer)
                {
                    answer = ans;
                }
            }
        }

        Console.WriteLine(answer);
    }

    private static int solve(int[,] map, int h, int w)
    {
        for (int turn = 0; turn < h * w; turn++)
        {
            bool process = false;
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    if (map[i, j] == turn)
                    {
                        if (j + 1 < w && map[i, j + 1] == -1)
                        {
                            map[i, j + 1] = turn + 1;
                            process = true;
                        }
                        if (j - 1 >= 0 && map[i, j - 1] == -1)
                        {
                            map[i, j - 1] = turn + 1;
                            process = true;
                        }
                        if (i + 1 < h && map[i + 1, j] == -1)
                        {
                            map[i + 1, j] = turn + 1;
                            process = true;
                        }
                        if (i - 1 >= 0 && map[i - 1, j] == -1)
                        {
                            map[i - 1, j] = turn + 1;
                            process = true;
                        }
                    }
                }
            }
            if (!process)
            {
                break;
            }
        }

        //print(map, h , w);

        int max = 0;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (map[i, j] >= max)
                {
                    max = map[i, j];
                }
            }
        }

        return max;
    }

    private static void print(int[,] map, int h, int w)
    {
        Console.WriteLine("****************");
        for (int i = 0; i < h; i++)
        {
            string line = "";
            for (int j = 0; j < w; j++)
            {
                line += " " + map[i, j];
            }
            Console.WriteLine(line);
        }
    }
}