from collections import deque
import copy
H, W = map(int, input().split())
S = [input() for _ in range(H)]

graph = [deque([]) for _ in range(H*W)]
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            if j+1 < W:
                if S[i][j+1] == ".":
                    graph[i*W+j].append(i*W+j+1)
                    graph[i*W+j+1].append(i*W+j)
            if i+1 < H:
                if S[i+1][j] == ".":
                    graph[i*W+j].append((i+1)*W+j)
                    graph[(i+1)*W+j].append(i*W+j)

def bfs(v, graph):
    d = [-1]*(H*W)
    stack = deque([v])
    d[v] = 0
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if d[w] == -1:
                d[w] = d[v]+1
                stack.appendleft(w)
        else:
            stack.pop()
    max_d = [0, 0]
    for i in range(H*W):
        if d[i] > max_d[0]:
            max_d = [d[i], i]
    return max_d

res = bfs(0, copy.deepcopy(graph))
res = bfs(res[1], graph)
print(res[0])