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

public struct Point
{
    public int X;
    public int Y;

    public Point(Point p)
    {
        X = p.X;
        Y = p.Y;
    }

    public Point(int x, int y)
    {
        X = x;
        Y = y;
    }

    public static bool operator ==(Point a, Point b)
    {
        return (a.X == b.X && a.Y == b.Y);
    }

    public static bool operator !=(Point a, Point b)
    {
        return !(a == b);
    }

    //objと自分自身が等価のときはtrueを返す
    public override bool Equals(object obj)
    {
        if (!(obj is Point))
        {
            return false;
        }

        Point p = (Point)obj;
        return (X == p.X && Y == p.Y);
    }

    //Equalsがtrueを返すときに同じ値を返す
    public override int GetHashCode()
    {
        return (X << 16) ^ Y;
    }

    public Point Clone()
    {
        return new Point(X, Y);
    }

    public void Reverse()
    {
        X = -X;
        Y = -Y;
    }

    public static Point operator +(Point a, Point b)
    {
        return new Point(a.X + b.X, a.Y + b.Y);
    }

    public static Point operator -(Point a, Point b)
    {
        return new Point(a.X - b.X, a.Y - b.Y);
    }

    public static Point operator *(Point a, int i)
    {
        return new Point(a.X * i, a.Y * i);
    }

    public static Point operator /(Point a, int i)
    {
        return new Point(a.X / i, a.Y / i);
    }
    public static Point operator +(Point a)
    {
        return new Point(+a.X, +a.Y);
    }

    public static Point operator -(Point a)
    {
        return new Point(-a.X, -a.Y);
    }

    public override string ToString()
    {
        return string.Format("({0},{1})", X, Y);
    }

    IEnumerable<Point> GetNeighbor_()
    {
        yield return new Point(X + 1, Y + 0);
        yield return new Point(X + 0, Y + 1);
        yield return new Point(X - 1, Y + 0);
        yield return new Point(X + 0, Y - 1);
    }

    public bool InRange(Point max)
    {
        return 0 <= X && X < max.X && 0 <= Y && Y < max.Y;
    }

    public IEnumerable<Point> GetNeighbor()
    {
        return GetNeighbor_().Where(p => p.InRange(Max));
    }

    public static Point Max;
}

public class Solution
{
    static int GetMaxStep(string[] maze, Point start)
    {
        int step = -1;
        if (maze[start.Y][start.X] == '#')
        {
            return step;
        }
        var visited = new HashSet<Point>();
        visited.Add(start);
        var currents = new List<Point>() { start };
        while (currents.Count > 0)
        {
            step++;
            var nexts = new List<Point>();
            foreach (var cur in currents)
            {
                foreach (var nei in cur.GetNeighbor())
                {
                    if (visited.Contains(nei) || maze[nei.Y][nei.X] == '#')
                    {
                        continue;
                    }
                    visited.Add(nei);
                    nexts.Add(nei);
                }
            }
            currents = nexts;
        }
        return step;
    }

    static int GetMaxStep(string[] maze)
    {
        var max = -1;
        for (int y = 0; y < Point.Max.Y; y++)
        {
            for (int x = 0; x < Point.Max.X; x++)
            {
                max = Math.Max(max, GetMaxStep(maze, new Point(x, y)));
            }
        }
        return max;
    }

    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var H = vals[0];
        var W = vals[1];
        Point.Max = new Point(W, H);
        var maze = new string[H];
        for (int i = 0; i < H; i++)
        {
            maze[i] = Console.ReadLine();
        }

        var max = GetMaxStep(maze);
        Console.WriteLine(max);
    }
}

Measured memory_bytes: 17736