from collections import defaultdict, deque
from itertools import product

H, W = map(int, input().split())
maze = [input() for _ in range(H)]
V = set()
E = defaultdict(list)
for i, j in product(range(H), range(W)):
    if maze[i][j] == '#': continue
    V |= {(i, j)}
    check = [(i+dx, j+dy) for dx, dy in [(1, 0), (0, 1)] if i+dx <= H-1 and j+dy <= W-1]
    for x, y in check:
        if maze[x][y] == '.': E[(i, j)].append((x, y)); E[(x, y)].append((i, j))
start = list(V)[0]

def bfs(s):
    q = deque([(s, 0)])
    dist = {v: -1 for v in V}
    while q:
        v, d = q.popleft()
        if dist[v] >= 0: continue
        dist[v] = d
        for u in E[v]:
            if dist[u] < 0:
                q.append((u, d+1))
    return dist

D1 = bfs(start)
v, d = sorted(D1.items(), reverse=True, key=lambda x: x[1])[0]
D2 = bfs(v)
print(max(D2.values()))