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

namespace AtCoder.D
{
    public class Program
    {
        public static long H { get; private set; }
        public static long W { get; private set; }
        public static char[,] S { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = ReadLongs();
            H = inputs[0];
            W = inputs[1];
            S = new char[H, W];
            for (int i = 0; i < H; i++)
            {
                var w = ReadText();
                for (int j = 0; j < W; j++)
                {
                    S[i, j] = w[j];
                }
            }

            var maxDist = 0L;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (S[i, j] == '#') continue;

                    var dist = Copy();
                    var queue = new Queue<SearchPoint>();
                    var startPoint = new SearchPoint(i, j, -1);
                    queue.Enqueue(startPoint);
                    dist[i, j] = 0;

                    while (queue.Count > 0)
                    {
                        Search_BFS(dist, queue);
                    }
                    maxDist = Math.Max(maxDist, GetMax(dist));
                }
            }

            return maxDist;
        }

        private static void Search_BFS(long[,] dist, Queue<SearchPoint> queue)
        {
            var p = queue.Dequeue();

            // 距離の記録
            var newDist = p.FromDist + 1;
            dist[p.H, p.W] = newDist;

            var nexts = new List<SearchPoint>
            {
                new SearchPoint (p.H + 1, p.W, newDist),
                new SearchPoint (p.H - 1, p.W, newDist),
                new SearchPoint (p.H, p.W + 1, newDist),
                new SearchPoint (p.H, p.W - 1, newDist),
            };

            foreach (var next in nexts)
            {
                // 迷路の壁 or 外
                if (next.H < 0 || next.H >= H) continue;
                if (next.W < 0 || next.W >= W) continue;
                if (S[next.H, next.W] == '#') continue;

                // 到達済み
                if (dist[next.H, next.W] > 0) continue;

                queue.Enqueue(next);
            }
        }

        private static void Search_DFS(long[,] depth, int h, int w, int fromDepth)
        {
            // 迷路の壁 or 外
            if (h < 0 || h >= H) return;
            if (w < 0 || w >= W) return;
            if (S[h, w] == '#') return;
            // すでに (x, y) に到達している
            if (depth[h, w] != -1) return;

            // 深さの記録
            var newDepth = fromDepth + 1;
            depth[h, w] = newDepth;

            // 4方向を試す
            Search_DFS(depth, h + 1, w, newDepth);
            Search_DFS(depth, h - 1, w, newDepth);
            Search_DFS(depth, h, w + 1, newDepth);
            Search_DFS(depth, h, w - 1, newDepth);
        }
        private static long[,] Copy()
        {
            var copy = new long[H, W];
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    copy[i, j] = -1;
                }
            }
            return copy;
        }
        private static long GetMax(long[,] depth)
        {
            var max = 0L;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    max = Math.Max(max, depth[i, j]);
                }
            }
            return max;
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }

    internal class SearchPoint
    {
        public int H { get; set; }
        public int W { get; set; }
        public int FromDist { get; set; }

        public SearchPoint(int h, int w, int fromDist)
        {
            H = h;
            W = w;
            FromDist = fromDist;
        }
    }
}
