[H,W] = list(map(int,input().split()))

M = []
for i in range(H):
    M.append(list(input()))

from collections import deque
def bfs(maze,r,c,sx,sy,gx,gy):
    d = [[float("inf")] * c for i in range(r)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0
    while que:
        p = que.popleft()
        if p[0] == gy and p[1] == gx:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if (0<=nx<r)and(0<=ny<c)and(maze[nx][ny]!="#")and(d[nx][ny]==float("inf")):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1
    return d[gy][gx]

out = 0
for sx in range(0,W):
    for gx in range(0,W):
        for sy in range(0,H):
            for gy in range(0,H):
                if (sx==gx)and(sy==gy):
                    continue
                d = bfs(M,H,W,sx,sy,gx,gy)
                if out<d<H*W:
                    out=d
print(out)
