import heapq



H,W = map(int, input().split())
S = [input() for _ in range(H)]

ans = 0
dyx = [(1,0), (0,1),(-1,0), (0,-1)]
for i in range(H):
    for j in range(W):
        dist = [[-1 for _ in range(W)] for _ in range(H)] 
        dist[i][j] = 0
        tmp = 0
        q = []
        heapq.heappush(q, (dist[i][j], i,j))
        while q:
            cost, y,x = heapq.heappop(q)
            for dy,dx in dyx:
                ny, nx = y+dy, x+dx
                if not 0 <= ny <= H-1 or not 0 <= nx <= W-1 or S[ny][nx] == "#":
                    continue
                if dist[ny][nx] == -1 or cost + 1 < dist[ny][nx]:
                    dist[ny][nx] = cost + 1
                    heapq.heappush(q, (dist[ny][nx], ny, nx))
                    



        for i in range(H):
            ans = max(ans, max(dist[i]))



print(ans)