from collections import deque

H, W = map(int, input().split())
s = []
for _ in range(H):
    s.append(input())
dh = [0, 0, 1, -1]
dw = [1, -1, 0, 0]
ans = 0
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            continue
        dismax = 0
        dist = [[-1 for j in range(W)] for i in range(H)]
        queue = deque([[i, j]])
        dist[i][j] = 0
        while len(queue) != 0:
            now = queue.popleft()
            h = now[0]
            w = now[1]
            for k in range(4):
                nh = h + dh[k]
                nw = w + dw[k]
                if nh < 0 or nw < 0 or nh >= H or nw >= W:
                    continue
                if dist[nh][nw] != -1 or s[nh][nw] == "#":
                    continue
                else:
                    dist[nh][nw] = dist[h][w] + 1
                    dismax = max(dist[nh][nw], dismax)
                    queue.append([nh, nw])
        print(dist)
        ans = max(ans, dismax)
print(ans)