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 = GetDistTable();
                    var queue = new Queue<Point>();
                    var startPoint = new Point(i, j);
                    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<Point> queue)
        {
            var p = queue.Dequeue();

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

            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] > -1) continue;

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

                queue.Enqueue(next);
            }
        }

        private static long[,] GetDistTable()
        {
            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 Point
    {
        public int H { get; set; }
        public int W { get; set; }

        public Point(int h, int w)
        {
            H = h;
            W = w;
        }
    }
}


Measured memory_bytes: 17744