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>();
            HashSet<int>[] conn = new HashSet<int>[H*W+1];

            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;
                    }
                }
            }
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    var x = mtx[i][j];
                    if (x < 0) continue;

                    conn[x] = new HashSet<int>();

                    if (i > 0)
                    {
                        if (mtx[i - 1][j] > 0)
                        {
                            conn[x].Add(mtx[i - 1][j]);

                        }
                    }
                    if (j > 0)
                    {
                        if (mtx[i][j - 1] > 0)
                        {
                            conn[x].Add(mtx[i][j-1]);
                        }
                    }
                    if (i < H-1)
                    {
                        if (mtx[i +1][j] > 0)
                        {
                            conn[x].Add(mtx[i +1][j]);

                        }
                    }
                    if (j < W - 1)
                    {
                        if (mtx[i][j+1] > 0)
                        {
                            conn[x].Add(mtx[i][j+1]);

                        }
                    }

                }
            }

                    var res = 0;
            foreach(var p1 in points)
            {
                added = new HashSet<int>();
                added.Add(p1);
                var dist = recursive(conn[p1], 0, points.Count, conn);
                res = Math.Max(res, dist);
            }
            Console.WriteLine(res);

        }
        static HashSet<int> added = new HashSet<int>();



        private static int recursive(HashSet<int> conn, int dist, int count, HashSet<int>[] allConn)
        {


            if (added.Count == count) return dist;
            HashSet<int> conns = new HashSet<int>();
            foreach (var px in conn)
            {
                foreach(var x in allConn[px]){
                    conns.Add(x);
                }
                added.Add(px);
            }
            if (conns.Count == 0) return dist;
            return recursive(conns, dist + 1, count, allConn);
        }

        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;
        }
    }

}


Measured memory_bytes: 28236