import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

long h;
long w;

void main()
{
    scan(h, w);
    auto s = new string[](h);
    foreach (i; iota(h))
        s[i] = sread();
    auto starts = new Pair[](0);
    foreach (i; iota(h))
        foreach (j; iota(w))
            starts ~= Pair(i, j);

    long max_dist;
    foreach (e; starts)
    {
        max_dist = max(s.rootlen(e), max_dist);
    }
    max(0, max_dist).writeln();
}

auto rootlen(T)(T s, Pair p)
{
    // 幅優先探索で一番遠い点を見つける
    // スタート地点がp
    auto dist = new long[][](h, w);
    dist[p.x][p.y] = -1;
    auto Q = DList!Pair(p);
    while (!Q.empty)
    {
        auto current = Q.front;
        Q.removeFront();
        if (current.x - 1 >= 0 && dist[current.x - 1][current.y] == 0)
        {
            if (s[current.x - 1][current.y] != '#')
            {
                Q.insertBack(Pair(current.x - 1, current.y));
                dist[current.x - 1][current.y] = dist[current.x][current.y] + 1;
            }
            else
                dist[current.x - 1][current.y] = -1;
        }
        if (current.x + 1 < h && dist[current.x + 1][current.y] == 0)
        {
            if (s[current.x + 1][current.y] != '#')
            {
                Q.insertBack(Pair(current.x + 1, current.y));
                dist[current.x + 1][current.y] = dist[current.x][current.y] + 1;
            }
            else
                dist[current.x + 1][current.y] = -1;

        }
        if (current.y - 1 >= 0 && dist[current.x][current.y - 1] == 0)
        {
            if (s[current.x][current.y - 1] != '#')
            {
                Q.insertBack(Pair(current.x, current.y - 1));
                dist[current.x][current.y - 1] = dist[current.x][current.y] + 1;
            }
            else
                dist[current.x][current.y - 1] = -1;
        }
        if (current.y + 1 < w && dist[current.x][current.y + 1] == 0)
        {
            if (s[current.x][current.y + 1] != '#')
            {
                Q.insertBack(Pair(current.x, current.y + 1));
                dist[current.x][current.y + 1] = dist[current.x][current.y] + 1;
            }
            else
                dist[current.x][current.y + 1] = -1;
        }
    }
    long maxdist;
    foreach (i; iota(h))
    {
        foreach (j; iota(w))
        {
            maxdist = max(dist[i][j], maxdist);
        }
    }
    return maxdist + 1;
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}
