using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System;

public class P
{
    public int x { get; set; }
    public int y { get; set; }
}

public class Hello
{
    public static int ans = 0;
    public static int[] dx, dy;
    public static int h, w;
    public static bool[,] map;
    public static void Main()
    {
        dx = new int[] { 0, 1, 0, -1 };
        dy = new int[] { 1, 0, -1, 0 };
        string[] line = Console.ReadLine().Trim().Split(' ');
        h = int.Parse(line[0]);
        w = int.Parse(line[1]);
        map = new bool[h, w];
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
                if (s[j] == '.') map[i, j] = true;
        }
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
                if (map[i, j]) getAns(i, j);
        Console.WriteLine(ans);
    }
    static void getAns(int sx, int sy)
    {
        var t = new int[h, w];
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++) t[i, j] = 1000; ;
        var q = new Queue<P>();
        q.Enqueue(new P { x = sx, y = sy });
        t[sx, sy] = 0;
        while (q.Count() > 0)
        {
            var a = q.Dequeue();
            var aa = t[a.x, a.y];
            for (int i = 0; i < 4; i++)
            {
                var nx = a.x + dx[i];
                var ny = a.y + dy[i];
                if (nx >= 0 && nx < h && ny >= 0 && ny < w && map[nx, ny] && t[nx, ny] > t[a.x, a.y])
                {
                    t[nx, ny] = t[a.x, a.y] + 1;
                    ans = Max(ans, t[nx, ny]);
                    q.Enqueue(new P { x = nx, y = ny });
                }
            }
        }
    }
}
