using System;
using System.Linq;

public class AtCoder_151_D
{
    public static void Main()
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int[] nums = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int h = nums[0];
        int w = nums[1];

        int size = h * w;

        // Wallの時true
        bool[] nodes = new bool[size];
        int index = 0;
        for (int y = 0; y < h; y++)
        {
            string line = Console.ReadLine();
            for (int x = 0; x < w; x++)
            {
                nodes[index] = line[x] == '#';
                index++;
            }
        }

        int[,] weight = new int[size, size];
        for (int i = 0; i < size; i++)
        {
            int iY = i / w;
            int iX = i % w;
            for (int j = 0; j < size; j++)
            {
                weight[i, j] = 1000;
                int jY = j / w;
                int jX = j % w;
                if (Math.Abs(iY - jY) == 1 && iX == jX ||
                    Math.Abs(iX - jX) == 1 && iY == jY)
                {
                    if (nodes[i] == false && nodes[j] == false)
                    {
                        weight[i, j] = 1;
                    }
                }
            }
        }

        for (int k = 0; k < size; k++)
        {
            for (int i = 0; i < size; i++)
            {
                if (weight[i, k] >= 1000) continue;
                for (int j = 0; j < size; j++)
                {
                    if (weight[k, j] >= 1000) continue;
                    weight[i, j] = Math.Min(weight[i, j], weight[i, k] + weight[k, j]);
                }
            }
        }

        int max = 0;
        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size; j++)
            {
                if (weight[i, j] < 1000)
                {
                    max = Math.Max(max, weight[i, j]);
                }
            }
        }

        Console.WriteLine(max);
    }
}
