#D
from collections import deque
H,W = map(int,input().split())
S = [list(str(input())) for i in range(H)]

MAX = 0
for i in range(H):
    for j in range(W):
        s = [i,j]
        dist = [[-1 for a in range(W)] for b in range(H)]
        
        dist[i][j] = 0
        de = deque([s])
        while de:
            d = de.popleft()
            h,w = d
            di = dist[h][w]
            if h > 0:
                if S[h-1][w] == "." and dist[h-1][w] < 0:
                    dist[h-1][w] = di+1
                    de.append([h-1,w])
            if h < H-1:
                if S[h+1][w] == "." and dist[h+1][w] < 0:
                    dist[h+1][w] = di+1
                    de.append([h+1,w])
            if w > 0:
                if S[h][w-1] == "." and dist[h][w-1] < 0:
                    dist[h][w-1] = di+1
                    de.append([h,w-1])
            if w < W-1:
                if S[h][w+1] == "." and dist[h][w+1] < 0:
                    dist[h][w+1] = di+1
                    de.append([h,w+1])
                    
        for h in range(H):
            for w in range(W):
                MAX = max(MAX,dist[h][w])
                
print(MAX)
        
        
        
