# D
from collections import deque
INF = float('inf')
h, w = map(int, input().split())
maps = []

for _ in range(h):
    lst = list(input())
    maps.append(lst)

def bfs(start,goal, maps, distance, height, width):
    d = deque()
    d.append(start)
    sx, sy = start
    distance[sx][sy] = 0
    
    while d:
        now = d.pop()
        nowx, nowy = now
        
        if nowx==goal[0] and nowy==goal[1]:
            break
        
        for i in range(0, 4):
            nx, ny = nowx + [1, 0, -1, 0][i], nowy + [0, 1, 0, -1][i]
            if (0<=nx<height)and(0<=ny<width):
                if (maps[nx][ny] == '.') and (distance[nx][ny] == -1):
                    d.append((nx, ny))
                    distance[nx][ny] = distance[nowx][nowy] + 1
    return distance[goal[0]][goal[1]]

cand = []
for sx in range(h):
    for sy in range(w):
        for gx in range(h):
            for gy in range(w):
                if maps[sx][sy] == '#':
                    continue
                distance = [[-1 for _ in range(w)] for _ in range(h)]
                cand.append(bfs((sx, sy),(gx, gy), maps, distance, h, w))
print(max(cand))