from collections import deque
H, W = [int(x) for x in input().split()]
S = [input() for _ in range(H)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
ans = 0
for y in range(H):
    for x in range(W):
        if S[y][x] == '#': continue 
        maze = [[-1 for _ in range(W)] for _ in range(H)]
        maze[y][x] = 0
        d = deque([(x, y)])
        while len(d):
            x, y = d.pop()
            now = maze[y][x]
            for i in range(4):
                nx, ny = [x + dx[i], y + dy[i]]
                if nx < 0 or nx > W-1 or ny < 0 or ny > H-1: continue
                if S[ny][nx] == '#': continue
                if maze[ny][nx] == -1 or maze[ny][nx] > now+1:
                    maze[ny][nx] = now+1
                    d.append((nx, ny))
        for m in maze:
            ans = max(ans, max(m))
print(ans)  
