from collections import deque

def bfs(s, visited, sy, sx, gy, gx):

    queue = deque([sy, sx])
    visited[sy][sx] = 0 

    while queue:
        
        y = queue.popleft()
        x = queue.popleft()
        

        if [y, x] == [gy, gx]:
            return visited[y][x]
        
        for (i, j) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            
            new_y = y + i
            new_x = x + j

            if (0 <= new_y < h) and (0 <= new_x < w):

                if s[new_y][new_x] == '.' and visited[new_y][new_x] == -1:
                        
                    visited[new_y][new_x] = visited[y][x] + 1
                    queue.append(new_y)
                    queue.append(new_x)


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

position = []
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            position.append([i, j])

position_set = []
a = len(position)
for i in range(a):
    for j in range(a):
        position_set.append(position[i] + position[j])

ans =[]
for i in position_set:
    visited = [[-1]*w for _ in range(h)] 
    ans.append(bfs(s, visited, i[0], i[1], i[2], i[3]))


print(max(ans))