from collections import deque



H,W = map(int, input().split())
S = [input() for _ in range(H)]

ans = 0
dyx = [(1,0), (0,1),(-1,0), (0,-1)]
for i in range(H):
    for j in range(W):
        dist = [[-1 for _ in range(W)] for _ in range(H)] 
        dist[i][j] = 0
        tmp = 0
        q = deque()
        q.append((i,j))
        while q:
            y,x = q.popleft()
            for dy,dx in dyx:
                ny, nx = y+dy, x+dx
                if not 0 <= ny <= H-1 or not 0 <= nx <= W-1 or S[ny][nx] == "#":
                    continue
                if dist[ny][nx] == -1 or dist[y][x] + 1 < dist[ny][nx]:
                    q.append((ny, nx))
                    dist[ny][nx] = dist[y][x] + 1
                    tmp = max(tmp, dist[ny][nx])


        for i in range(H):
            ans = max(ans, max(dist[i]))



print(ans)