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

namespace abc151_d
{
    class Program
    {
        static void Main(string[] args)
        {

            var HW = GetIntList();
            var H = HW[0];
            var W = HW[1];

            var map = new int[H + 2, W + 2];

            for (int i = 1; i <= H; i++)
            {
                var l = GetStr();
                for (int j = 1; j <= W; j++)
                    if (l[j - 1] == '.') map[i, j] = 1;
            }

            int r = 0;

            //for (int i = 0; i <= H + 1; i++)
            //{
            //    for (int j = 0; j <= W + 1; j++)
            //        Console.Write(map[i, j]);
            //    Console.WriteLine();
            //}

            for (int sy = 1; sy <= H; sy++)
            {
                for (int sx = 1; sx <= W; sx++)
                {

                    for (int ey = 1; ey <= H; ey++)
                    {
                        for (int ex = 1; ex <= W; ex++)
                        {
                            if ((sx == ex && sy == ey) || map[sy, sx] == 0 || map[ey, ex] == 0) continue;
                            //Console.Write($"{sx}, {sy} - {ex}, {ey}");
                            r = Math.Max(r, Resolve(map, new int[] { sy, sx }, new int[] { ey, ex }));
                            //Console.WriteLine($" = {r}");
                        }
                    }

                }
            }

          Console.WriteLine(r);

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="map"></param>
        /// <param name="S">スタート y, x</param>
        /// <param name="G">ゴール y, x</param>
        /// <returns></returns>
        public static int Resolve(int[,] map, int[] S, int[] G) 
        {
            var mapr = new int[map.GetLength(0), map.GetLength(1)];

            var Q = new Queue<int[]>();

            Q.Enqueue(S.ToArray());

            mapr[S[0], S[1]] = 1;

            var offsetList = new List<int[]>();

            offsetList.Add(new int[] { -1, 0 });
            offsetList.Add(new int[] { 1, 0 });
            offsetList.Add(new int[] { 0, -1 });
            offsetList.Add(new int[] { 0, 1 });

            while (Q.Count != 0)
            {
                var n = Q.Dequeue();

                foreach (var offset in offsetList)
                    if (map[n[0] + offset[0], n[1] + offset[1]] == 1 && mapr[n[0] + offset[0], n[1] + offset[1]] == 0)
                    {
                        Q.Enqueue(new int[] { n[0] + offset[0], n[1] + offset[1] });
                        mapr[n[0] + offset[0], n[1] + offset[1]] = mapr[n[0], n[1]] + 1;
                    }

                //for (int i = 0; i < map.GetLength(0); i++)
                //{
                //    for (int j = 0; j < map.GetLength(1); j++)
                //        Console.Write(mapr[i, j].ToString("|00"));
                //    Console.WriteLine();
                //}
                //Console.ReadKey();
            }

            return mapr[G[0], G[1]] - 1;
        }


        public static string GetStr() => Console.ReadLine();
        public static int GetInt() => int.Parse(Console.ReadLine());
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static decimal GetDecimal() => decimal.Parse(Console.ReadLine());

        public static List<string> GetStrList() => Console.ReadLine().Split(' ').ToList();
        public static List<int> GetIntList() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        public static List<long> GetLongList() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
        public static List<double> GetDoubleList() => Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList();
        public static List<decimal> GetDecimalList() => Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList();



    }
}
