from collections import deque

def bfs(grid, sy, sx, wall):
    queue = deque([])
    queue.append([sy, sx, 0])
    visited = {}
    visited[(sy,sx)] = 0
    dxy = [(1,0), (-1,0), (0,1), (0,-1)]
    while queue:
        y,x,cnt = queue.popleft()
        for dy, dx in dxy:
            y_,x_ = y+dy,x+dx
            if grid[y_][x_] == wall or (y_,x_) in visited:
                continue
            queue.append([y_,x_,cnt+1])
            visited[(y_,x_)] = cnt+1
    return visited

h,w = map(int, input().split())
wall = '#'
edges = [wall] * (w+2)
grid = [edges]
start = []
for i in range(h):
    s = input()
    grid.append([wall] + list(s) + [wall])
    for j in range(1,w+1):
        if start == [] and grid[i][j] == '.':
            start = [i,j]
grid.append(edges)

visited = bfs(grid, start[0], start[1], wall)
mx = 0
pos = []
for k,v in visited.items():
    if v > mx:
        mx = v
        pos = k
# print(start, pos)
visited = bfs(grid, pos[0], pos[1], wall)
print(max(visited.values()))
