from collections import deque

h, w = map(int, input().split())
maze = [0] * h
for i in range(h):
    maze[i] = list(input())
# print(maze)
INF = int(1e10 + 7)
d = [[INF] * w for i in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

# que = deque([('x', 'y')])
# print(que)
# print(que[0])

def bfs(x, y):
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    que = deque([(x, y)])
    d[x][y] = 0

    while len(que) != 0:
        val = que.popleft()

        for i in range(4):
            nx = val[0] + dx[i]
            ny = (val[1] + dy[i])
            if (0 <= nx < h and 0 <= ny < w and maze[nx][ny] != '#' and d[nx][ny] == INF):
                que.append((nx, ny))
                d[nx][ny] = d[val[0]][val[1]] + 1
    maxval = 0
    for i in range(h):
        for j in range(w):
            if d[i][j] > maxval and d[i][j] != INF:
                maxval = d[i][j]
    return maxval

maxans = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] != '#':
            if bfs(i, j) > maxans:
                maxans = bfs(i, j)
print(maxans)