# -*- coding: utf-8 -*-
H, W = map(int, input().split(' '))
table = [[c for c in input()] for _ in range(H)]

def dfs(i, j):
    dists = [[-1 for c in range(W)] for _ in range(H)]

    buf = [(i, j, 0)]
    while buf:
        buf2 = []
        for i, j, d in buf:
            if dists[i][j] != -1:
                continue

            else:
                dists[i][j] = d
                # if dists[i][j] == -1:
                #     dists[i][j] = d
                # else:
                #     dists[i][j] = min(dists[i][j], d)

                if 0 <= i-1 < H and table[i-1][j] == '.':
                    if dists[i-1][j] == -1:
                        buf2.append((i-1, j, d+1))

                if 0 <= i+1 < H and table[i+1][j] == '.':
                    if dists[i+1][j] == -1:
                        buf2.append((i+1, j, d+1))

                if 0 <= j-1 < W and table[i][j-1] == '.':
                    if dists[i][j-1] == -1:
                        buf2.append((i, j-1, d+1))

                if 0 <= j+1 < W and table[i][j+1] == '.':
                    if dists[i][j+1] == -1:
                        buf2.append((i, j+1, d+1))

        buf = buf2
        # print(buf)

    # for d in dists:
    #     print(d)

    return max(max(dists))

# print(table)

ans = 0
for i in range(H):
    for j in range(W):
        if table[i][j] == '.':
            n = dfs(i, j)
            ans = max(ans, n)


print(ans)

