using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine().Split().Select(long.Parse).ToList();
            var H = input1[0];
            var W = input1[1];

            var maze = new int[H, W];
            for (int i = 0; i < H; i++)
            {
                var S = Console.ReadLine().Select(s => s == '.' ? 0 : -1).ToList();
                for (int j = 0; j < W; j++)
                {
                    maze[i, j] = S[j];
                }
            }

            var ans = 0;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    var count = Count(Copy(maze), i, j);
                    if (ans < count) ans = count;
                }
            }

            Console.WriteLine(ans);
        }

        private static int[,] Copy(int[,] source)
        {
            var ret = new int[source.GetLength(0), source.GetLength(1)];
            Array.Copy(source, ret, source.Length);
            return ret;
        }

        private static int Count(int[,] maze, int x, int y)
        {
            var list = new List<Tuple<int, int>>() { new Tuple<int, int>(x, y) };
            maze[x, y] = 1;

            var count = -1;
            while (list.Any())
            {
                count++;
                list = FillAround(maze, list);
            }

            return count;
        }

        private static List<Tuple<int, int>> FillAround(int[,] maze, List<Tuple<int, int>> list)
        {
            var nextList = new List<Tuple<int, int>>();
            list.ForEach(s => nextList.AddRange(FillAround(maze, s)));
            return nextList;
        }

        private static List<Tuple<int, int>> FillAround(int[,] maze, Tuple<int, int> item)
        {
            var nextList = new List<Tuple<int, int>>();
            var x = item.Item1;
            var y = item.Item2;

            Fill(maze, nextList, x - 1, y);
            Fill(maze, nextList, x + 1, y);
            Fill(maze, nextList, x, y - 1);
            Fill(maze, nextList, x, y + 1);

            return nextList;
        }

        private static void Fill(int[,] maze, List<Tuple<int, int>> list, int x, int y)
        {
            if (x < 0 || x >= maze.GetLength(0) || y < 0 || y >= maze.GetLength(1)) return;
            if (maze[x, y] == 0)
            {
                maze[x, y] = 1;
                list.Add(new Tuple<int, int>(x, y));
            }
        }
    }
}
