h, w = map(int, input().split())
D = [list(input()) for _ in range(h)]
# 　D[高さ][横]
flag = 0
for i in range(h):
    for j in range(w):
        if D[i][j] == ".":
            start = (i, j)
            flag = 1
            break
    if flag:
        break

di = [1, 0, -1, 0]
dj = [0, 1, 0, -1]


def check(i, j):
    if i >= 0 and i < h and j >= 0 and j < w:
        cond = True
    else:
        cond = False
    return cond


def dfs(start, D):
    res = 0
    basho = (0, 0)
    dist = [[-1] * w for _ in range(h)]
    sy, sx = start
    dist[sy][sx] = 0
    stack = []
    stack.append(start)
    while stack:
        nowi, nowj = stack.pop()
        kyori = dist[nowi][nowj]
        for i in range(4):
            newi = nowi + di[i]
            newj = nowj + dj[i]
            if check(newi, newj):
                if dist[newi][newj] >= 0:
                    continue
                if D[newi][newj] == "#":
                    continue
                dist[newi][newj] = kyori + 1
                if res < kyori + 1:
                    res = kyori + 1
                    basho = (newi, newj)
                stack.append((newi, newj))
    return res, basho


_, temp = dfs(start, D)
ans, _ = dfs(temp, D)
print(ans)
