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

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var H = input[0];
            var W = input[1];
            var S = new string[H];
            for (int i = 0; i < H; i++) S[i] = Read();
            var ans = 0;
            var x = new int[] { 1, 0, -1, 0 };
            var y = new int[] { 0, 1, 0, -1 };
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    var cnt = new int[H, W];
                    var que = new Queue<int[]>();
                    que.Enqueue(new int[] { i, j, 0 });
                    while (que.Any())
                    {
                        var chk = que.Dequeue();
                        var h = chk[0];
                        var w = chk[1];
                        var m = chk[2];
                        for (int k = 0; k < 4; k++)
                        {
                            var chkH = h + x[k];
                            var chkW = w + y[k];
                            if (chkH >= 0 && chkH < H && chkW >= 0 && chkW < W)
                            {
                                if (cnt[chkH, chkW] == 0 && S[chkH][chkW] != '#')
                                {
                                    cnt[chkH, chkW] = m + 1;
                                    que.Enqueue(new int[] { chkH, chkW, m + 1 });
                                }
                            }
                        }
                    }
                    for (int k = 0; k < H; k++)
                    {
                        for (int l = 0; l < W; l++)
                        {
                            if (cnt[k, l] > ans) ans = cnt[k, l];
                        }
                    }
                }
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}