from collections import deque
import copy
H, W = map(int, input().split())
field = []
for i in range(H):
    field.append(list(input()))
f = copy.deepcopy(field)

def BFS(x, y, field):
    cnt = [[0 for _ in range(W)] for _ in range(H)]
    queue = deque()
    queue.append((x, y))
    while queue:
        x, y = queue.popleft()
        if(field[x][y] == "#"):
            continue        
            
        field[x][y] = "#"
        for dx, dy in ((-1, 0), (1, 0), (0, -1), (0, 1)):
            nx = x + dx
            ny = y + dy
            if(nx < 0 or nx >= H or ny < 0 or ny >= W):
                continue
            queue.append((nx, ny))
            if(field[nx][ny] != "#"):
                cnt[nx][ny] = cnt[x][y] + 1
    return max(max(cnt))

ans = 0
for i in range(H):
    for j in range(W):
        if(field[i][j] == "#"):
            continue
        ans = max(ans, BFS(i, j, f))
        f = copy.deepcopy(field)
print(ans)