from collections import deque

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

visited = [[False] * (w + 5) for _ in range(h + 5)]
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#': continue

        q = deque()
        q.append([i, j, 0])
        dirr = [[1, 0], [0, 1], [-1, 0], [0, -1]]
        while len(q) != 0:
            x, y, z = q.popleft()
            ans = max(ans, z)
            visited[x][y] = True
            for p in range(4):
                nx, ny = x + dirr[p][0], y + dirr[p][1]
                if 0 <= nx < h and 0 <= ny < w:
                    if not visited[nx][ny] and s[nx][ny] == '.':
                        q.append([nx, ny, z + 1])
print(ans)