from collections import deque


def bfs(y, x, H, W, S):
    dirs = [(-1, 0), (0, -1), (1, 0), (0, 1)]
    q = deque()
    q.append((y, x, 0))
    max_depth = 0
    while q:
        y, x, depth = q.popleft()
        S[y][x] = '#'
        max_depth = max(max_depth, depth)
        for dy, dx in dirs:
            ny, nx = y + dy, x + dx
            if S[ny][nx] == '.':
                q.append((ny, nx, depth+1))
    return max_depth


def solve():
    H, W = map(int, input().split())
    S = list()
    S.append(['#'] * (W+2))
    for _ in range(H):
        buf = input()
        S.append(list('#' + buf + '#'))
    S.append(['#'] * (W+2))

    dist_max = 0
    for y in range(H):
        for x in range(W):
            if S[y+1][x+1] == '.':
                #print(y, x)
                d = bfs(y+1, x+1, H, W, S.copy())
                dist_max = max(d, dist_max)
    print(dist_max)


if __name__ == '__main__':
    solve()
