h, w = map(int, input().split())
f = [input() for _ in range(h)]

def next(pos):
    x, y = pos
    ret = []
    for dx, dy in [(0, -1), (0, 1), (-1, 0), (1, 0)]:
        i = x + dx
        j = y + dy
        if 0 <= i < h and 0 <= j < w and f[i][j] != '#':
            ret.append((i, j))
    return ret

ans = 0
for i in range(h):
    for j in range(w):
        s = {(i, j)}
        ng = set()
        dis = 0
        while s:
            t = set()
            for p in s:
                ng.add(p)
                for x, y in next(p):
                    if (x, y) not in ng:
                        t.add((x, y))
            s = t
            dis += 1
        ans = max(ans, dis - 1)
print(ans)