from collections import deque

H,W = map(int, input().split())
fields = []
for i in range(H):
    fields.append(list(input()))
# print(fields)

mvs = [(1,0),(-1,0),(0,1),(-1,0)]

ans = 0
for i1 in range(H):
    for j1 in range(W):
        if fields[i1][j1] == "#":continue
        s = (i1,j1)
        # 探索
        q = deque([])
        q.append(s)
        used = [[0]*W for i in range(H)]
        while len(q) > 0:
            h,w = q.popleft()
            for dh,dw in mvs:
                if 0 <= h+dh < H and 0 <= w+dw < W:
                    if used[h+dh][w+dw]==0 and fields[h+dh][w+dw]==".":
                        q.append((h+dh,w+dw))
                        used[h+dh][w+dw] = used[h][w] + 1
        for i in range(H):
            for j in range(W):
                ans = max(ans, used[i][j])
print(ans)