from collection import deque

def bfs(loc):
    global tem_ans
    d = [[float('inf')] * w for i in range(h)]

    dx = [1,0,-1,0]
    dy = [0,1,0,-1]

    que = deque([])
    que.append(loc)
    d[loc[0]][loc[1]] = 0

    while que:
        p = popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] == '.' and d[nx][ny] == float('inf'):
                d[nx][ny] = d[p[0]][p[1]] + 1
                que.append([nx,ny])

                if tem_ans < d[nx][ny]:
                    tem_ans = d[nx][ny]
    return tem_ans

h,w = map(int,input().split())
maze = [list(input()) for i in range(h)]
ans = 0
tem_ans = 0

loc = []
for i in range(h):
    for j in range(w):
        if maze[i][j] != '#':
            loc = [i,j]
        else:
            continue
        ans = max(ans,bfs(loc))

print(ans)
