using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        int[] arr = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        int h = arr[0];
        int w = arr[1];
        int[] dh = { 0, 1, 0, -1 };
        int[] dw = { -1, 0, 1, 0 };
        var ans = 0;
        var list = new List<char[]>();
        for(int i = 0; i < h; i++)
        {
            list.Add(Console.ReadLine().ToCharArray());
        }
        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
            {
                var res = 0;
                var que = new Queue<(int h, int w, int dis)>();
                bool[,] boolMap = new bool[h, w];
                que.Enqueue((i, j, 0));
                boolMap[i, j] = true;
                while (que.Count() > 0)
                {
                    var nq = que.Dequeue();
                    for(int k = 0; k < 4; k++)
                    {
                        int nh = nq.h + dh[k];
                        int nw = nq.w + dw[k];
                        res = Math.Max(res, nq.dis);
                        if(0<=nh && nh < h && 0 <= nw && nw < w)
                        {
                            if (boolMap[nh, nw] || list[nh][nw] == '#') continue;
                            que.Enqueue((nh, nw, nq.dis + 1));
                            boolMap[nh, nw] = true;
                        }
                    }

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

  



}

   