h,w = map(int,input().split())
s = []
v = [(1, 0), (0, 1), (-1, 0), (0, -1)]
for i in range(h):
    s += [input()]
ans = 0


def dfs(d, i, j, c):
    if i < 0 or h <= i or j < 0 or w <= j:
        return
    if s[i][j] == '#' or d[i][j] <= c:
        return

    d[i][j] = c
    for y,x in v:
        dfs(d, i+y, j+x, c+1)


for i in range(h*w): 
    for j in range(h*w):
        d = [[h * w] * w for i in range(h)]
        p = (i // w, i % w)
        q = (j // w, j % w)
        if s[p[0]][p[1]] == '#' or s[q[0]][q[1]] == '#':
            continue
        dfs(d, p[0], p[1], 0)
        if d[q[0]][q[1]] < h*w:
            ans = max(d[q[0]][q[1]], ans)

print(ans)