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 sy = 1; sy <= H; sy++)
                for (int sx = 1; sx <= W; sx++)
                    if (map[sy, sx] == 1)
                        r = Math.Max(r, ResolveMaze(map, new int[] { sy, sx }));
            
            Console.WriteLine(r);
        }

        /// <summary>
        /// 迷路最短経路探索（幅優先）
        /// </summary>
        /// <param name="map"></param>
        /// <param name="S">スタート y, x</param>
        /// <returns></returns>
        public static int ResolveMaze(int[,] map, int[] S) 
        {
            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 });

            int r = 0;

            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;
                        r = Math.Max(mapr[n[0], n[1]] + 1, r);
                    }

                //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 r - 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();



    }
}


Measured memory_bytes: 13524