import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

dxdy = [(0,1),(1,0),(0,-1),(-1,0)]

h,w = map(int, input().split())
board = [list(input()) for i in range(h)]

for i in range(h):
    for j in range(w):
        if board[i][j] == ".":
            x, y = i, j


from heapq import heappop, heappush

def dfs(sx, sy):
    dist = [[float("inf")]*w for i in range(h)]
    heap = [(0, sx, sy)]
    while heap:
        c,x,y = heappop(heap)
        if dist[x][y] <= c:
            continue
        dist[x][y] = c
        for dx, dy in dxdy:
            nx = x + dx
            ny = y + dy
            if 0<=nx<h and 0<=ny<w and board[nx][ny] == "." and dist[nx][ny] > c+1:
                heappush(heap, (c+1, nx, ny))
    
    tmp = 0
    rx, ry = 0, 0
    for i in range(h):
        for j in range(w):
            if dist[i][j] != float("Inf") and tmp < dist[i][j]:
                tmp = dist[i][j]
                rx,ry = i,j
    return tmp, rx, ry

ans = 0


for i in range(10):
    r, x,y = dfs(x, y)
print(r)