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
    
def bfs(p, q, c):
    distance = {(p, q):0}
    que = deque([(p, q)])
    reached = {(p, q):1}
    
    while len(que) > 0: 
        (y, x) = que.popleft()
        if c[y][x] == '#':
            continue
        
        reached[(y, x)] = 1
        try:
            if reached[(y+1, x)] == 1:
                pass
        except KeyError:
            if c[y+1][x] == '.':
                que.append((y+1, x))
                distance[(y+1, x)] = distance[(y, x)] + 1
        
        try:
            if reached[(y-1, x)] == 1:
                pass
        except KeyError:
            if c[y-1][x] == '.':
                que.append((y-1, x))
                distance[(y-1, x)] = distance[(y, x)] + 1
        
        try:
            if reached[(y, x+1)] == 1:
                pass
        except KeyError:
            if c[y][x+1] == '.':
                que.append((y, x+1))
                distance[(y, x+1)] = distance[(y, x)] + 1
        
        try:
            if reached[(y, x-1)] == 1:
                pass
        except KeyError:
            if c[y][x-1] == '.':
                que.append((y, x-1))
                distance[(y, x-1)] = distance[(y, x)] + 1
        
    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))
