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

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var INF = -1;
            var r = ReadSplit();
            var h = r[0].ToInt();
            var w = r[1].ToInt();
            var table = new string[h][];
            for (int i = 0; i < h; i++)
            {
                var r2 = Read();
                table[i] = new string[w];
                for (int j = 0; j < r2.Length; j++)
                {
                    table[i][j] = r2[j].ToString();
                }
            }

            var ans = 0;
            for (int k = 0; k < h; k++)
            {
                for (int l = 0; l < w; l++)
                {
                    
                    var q = new List<Tuple<int, int>>();
                    var dist = new int[h][];

                    for (int i = 0; i < h; i++)
                    {
                        dist[i] = new int[w];
                        for (int j = 0; j < w; j++)
                        {
                            dist[i][j] = INF;
                        }
                    }

                    var Add = new Action<int, int, int>((y, x, d) =>
                    {
                        if (table[y][x] == "#") return;
                        if (dist[y][x] != INF) return;
                        q.Add(new Tuple<int, int>(y, x));
                        dist[y][x] = d;
                        if (ans < d)
                        {
                            ans = d;
                        }
                    });

                    q.Add(new Tuple<int, int>(k, l));
                    dist[k][l] = 0;

                    while (q.Any())
                    {
                        var v = q[0]; q.RemoveAt(0);
                        var x = v.Item2;
                        var y = v.Item1;
                        var d = dist[y][x];
                        if (x + 1 < w) Add(y, x + 1, d + 1);
                        if (x - 1 >= 0) Add(y, x - 1, d + 1);
                        if (y + 1 < h) Add(y + 1, x, d + 1);
                        if (y - 1 >= 0) Add(y - 1, x, d + 1);
                    }
                }
            }
            WriteRead(ans);
        }

        public class ACWA
        {
            public int AC { get; set; }
            public int WA { get; set; }
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }
    }
}


public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }
}

