using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }


    public class Class1
    {
        static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, long>, long>();

        static long mod = 1000000007;
        static long[] factorial = new long[100001];
        static long[] invFactorial = new long[100001];

        private static void calcFanctorial(long N)
        {
            factorial[0] = 1;
            for(int i=1; i< N+1; i++)
            {
                factorial[i] = factorial[i - 1] * i;
                factorial[i] %= mod;
            }
            invFactorial[N] = inv(factorial[N]);
            for (int i = (int)N; i > 0; i--)
            {
                invFactorial[i - 1] = invFactorial[i] * i % mod;
            }

        }

        static void Main(string[] args)
        {

            var AA = ReadLongArr();
            long H = AA[0];
            long W = AA[1];
            var input = ReadCharMatrix(H);
            var mtx = CreateIntMatrix(H, W);

            List<Edge> edges = new List<Edge>();
            List<int> points = new List<int>();

            int p = 1;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (input[i][j] == '.')
                    {
                        mtx[i][j] = p;
                        points.Add(p);
                        p++;

                        if (i > 0)
                        {
                            if (mtx[i - 1][j] > 0)
                            {
                                edges.Add(new Edge { e1 = mtx[i - 1][j], e2 = mtx[i][j] });
                            }
                        }
                        if (j > 0)
                        {
                            if (mtx[i][j - 1] > 0)
                            {
                                edges.Add(new Edge { e1 = mtx[i][j - 1], e2 = mtx[i][j] });
                            }
                        }
                    }
                    else
                    {
                        mtx[i][j] = -1;
                    }
                }
            }


            var res = 0;
            foreach(var p1 in points)
            {
                var dist = 0;
                List<int> pp = new List<int>();
                pp.Add(p1);

                while (pp.Count < points.Count)
                {
                    dist++;
                    List<int> pp2 = new List<int>();
                    foreach (var px in pp)
                    {
                        foreach (var e in edges)
                        {
                            var p2 = e.getOtherSide(px);
                            if (p2 > 0 && !pp.Contains(p2))
                            {
                                pp2.Add(p2);
                            }
                        }
                    }
                    pp.AddRange(pp2);
                }

                res = Math.Max(res, dist);
            }
            Console.WriteLine(res);

        }

        private class Edge
        {
            public int e1;
            public int e2;

            public bool Equals(int f1, int f2)
            {
                return ((e1 == f1) && (e2 == f2)) || ((e1 == f2) && (e2 == f1));
            }
            public int getOtherSide(int e)
            {
                if (e1 == e) return e2;
                if (e2 == e) return e1;
                return -1;
            }
        }

        private static long nCm(long n, long m)
        {
            if (n < m) return 0;

             return (factorial[n] * invFactorial[m] % mod) * invFactorial[n-m] % mod;
        }

        public static long pow(long a, long b, long mod)
        {
            a %= mod;

            if (b <= 0) return 1;
            var t = pow(a, b / 2, mod);
            if ((b & 1) == 0) return t * t % mod;
            return t * t % mod * a % mod;
        }

        public static long Lcm(long a, long b)
        {
            return a * b % mod * inv(Gcd(a, b)) % mod;
        }

        public static long Lcm(long[] a)
        {
            List<long> vect = new List<long>();
            long lcm = 1;
            for (int i = 0; i < a.Count(); i++)
            {
                var factor = a[i] / GcdVector(vect, a[i]);
                vect.Add(factor);
                lcm = lcm * factor % mod;
            }
            return lcm;
        }

        static long GcdVector(List<long> a, long b)
        {
            long ma = 1;
            for (int i = 0; i < a.Count; i++)
                ma = ma * a[i] % b;
            return Gcd(b, ma);
        }

        public static long Gcd(long a, long b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }

        public static long pow(long a, long b) => pow(a, b, mod);
        public static long inv(long a) => pow(a, mod - 2);

        private static char[][] ReadCharMatrix(long h)
        {
            char[][] mtx = new char[h][];
            for(int i=0; i<h; i++)
            {
                var s = ReadString();
                mtx[i] = s.ToCharArray();
            }
            return mtx;
        }

        private static int[][] CreateIntMatrix(long h, long w)
        {
            int[][] mtx = new int[h][];
            for (int i = 0; i < h; i++)
            {
                mtx[i] = new int[w];
            }
            return mtx;
        }


        private static string ReadString()
        {
            return Console.ReadLine();
        }
        private static string[] ReadStringArr()
        {
            return Console.ReadLine().Split(' ');
        }
        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadLongArr()
        {
            string[] s = ReadStringArr();
            long[] l = new long[s.Length];
            for(int i=0; i<l.Length; i++)
            {
                l[i] = long.Parse(s[i]);
            }

            return l;
        }
    }

}
