n, m = map(int, input().split())
ar = []
for i in range(n):
    ar.append(list(input()))

dx = [1, -1, 0, 0]
dy = [0, 0, -1, -1]


res  = 0

for i in range(n):
    for j in range(m):
        if ar[i][j] == '.':
            vis = [[-1] * m for k in range(n)]
            queue = [i, j]
            vis[i][j] = 0
            while len(queue):
                x = queue.pop(0)
                y = queue.pop(0)
                for k in range(4):
                    x1 = x + dx[k]
                    y1 = y + dy[k]
                    if 0 <= x1 < n and 0 <= y1 < m and ar[x1][y1] == '.' and vis[x1][y1] == -1:
                        vis[x1][y1] = vis[x][y] + 1
                        res = max(res, vis[x1][y1])
                        queue.append(x1)
                        queue.append(y1)

print(res)
