from collections import deque

H, W = map(int, input().split())
#print("H={}, W={}".format(H, W))
S = [list(input()) for _ in range(H)] # input().split()だと分割されない！！！
#print(S)

def maxCost(s0, s1):
    """
    (s0, s1)から任意の道に最短経路で移動するとして、その中での最大コストを算出する
    """
    maxCost = 0
    visited = [[10**9 for _ in range(W)] for _ in range(H)] # そのマスへの移動の最小コスト
    q = deque([(s0, s1, 0)])
    visited[s0][s1] = 0

    while q:
        u0, u1, cost = q.popleft()
        #print("({}, {}), cost={}".format(u0, u1, cost))
        if u0 < H - 1 and S[u0+1][u1] == "." and visited[u0+1][u1] > cost+1:
            #print("first")
            visited[u0+1][u1] = cost+1
            maxCost = max(maxCost, cost+1)
            q.append((u0+1, u1, cost+1))
        if u0 > 0 and S[u0-1][u1] == "." and visited[u0-1][u1] > cost+1:
            #print("second")
            visited[u0-1][u1] = cost+1
            maxCost = max(maxCost, cost+1)
            q.append((u0-1, u1, cost+1))
        if u1 < W - 1 and S[u0][u1+1] == "." and visited[u0][u1+1] > cost+1:
            #print("third")
            visited[u0][u1+1] = cost+1
            maxCost = max(maxCost, cost+1)
            q.append((u0, u1+1, cost+1))
        if u1 > 0 and S[u0][u1-1] == "." and visited[u0][u1-1] > cost+1:
            #print("fourth")
            visited[u0][u1-1] = cost+1
            maxCost = max(maxCost, cost+1)
            q.append((u0, u1-1, cost+1))

    return maxCost

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, maxCost(i, j))
print(ans)
