from collections import deque

h, w = [int(v) for v in input().split()]

maze = []
for i in range(h):
    maze.append(list(input()))


def find(maze):
    for i in range(h):
        for j in range(w):
            if maze[i][j] == '.':
                return (i, j)
    return None

def contains(maze, closed, i, j):
    if i < 0 or i >= h:
        return False
    if j < 0 or j >= w:
        return False
    key = (i, j)
    if key in closed:
        return False
    closed.add(key)

    return True

def far(maze, p):
    q = deque([])

    i0 = p[0]
    j0 = p[1]
    q.append((i0, j0, 0))

    closed = set()
    closed.add((i0, j0))
    max_dist = 0
    max_p = None
    while len(q) > 0:
        e = q.popleft()
        
        i = e[0]
        j = e[1]
        cost = e[2] + 1
        for n in ((0, 1), (1, 0), (-1, 0), (0, -1)):
            ni = i + n[0]
            nj = j + n[1]
            nkey = (ni, nj)
            if not contains(maze, closed, ni, nj):
                continue
            if maze[ni][nj] != '.':
                continue
            q.append((ni, nj, cost))
            if max_dist < cost:
                max_dist = cost
                max_p = nkey
    return max_p, max_dist
    

p0 = find(maze)


p1, dist  = far(maze, p0)

while True:
    p2, max_dist = far(maze, p1)
    if dist == max_dist:
        break
    dist = max_dist
    p1 = p2

print(max_dist)

