from collections import deque

[H, W] = [int(i) for i in input().split()]
S = [0]*(H+2)
S[0] = ['#']*(W+2)
S[H+1] = ['#']*(W+2)

for i in range(1, H+1):
    row = ['#'] + list(input()) + ['#']
    S[i] = row

dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]
    
def bfs(p, q, c):
    distance = {(p, q):0}
    que = deque([(p, q)])
    reached = [[0]*(W+2) for k in range(H+2)]
    
    while len(que) > 0: 
        (y, x) = que.popleft()
        
        if c[y][x] == '#':
            continue
        
        reached[y][x] = 1
        
        for k in range(4):
            yy, xx = y + dy[k], x + dx[k]
            if reached[yy][xx] == 1 or c[yy][xx] == '#':
                continue
            else:
                distance[(yy, xx)] = distance[(y, x)] + 1
                que.append((yy, xx))
        
    distances = list(distance.values())
    return max(distances)

anss = [0]*(H*W)
times = 0

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] == '.':
            anss[times] = bfs(i, j, S)
        times += 1

print(max(anss))