from collections import deque


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


def solve():
    H, W = map(int, input().split())
    S = deque()
    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+2):
        for x in range(W+2):
            if S[y][x] == '.':
                d = bfs(y, x, H, W, S)
                dist_max = max(d, dist_max)
    print(dist_max)


if __name__ == '__main__':
    solve()
