def resolve():
    '''
    code here
    '''
    import collections
    import numpy as np
    H, W = [int(item) for item in input().split()]
    grid = [[item for item in input()] for _ in range(H)]

    def bfs(i,j):
        que = collections.deque([[i,j,0]])
        footprint = [[0 for _ in range(W)] for _ in range(H)]
        cnt = 0

        while len(que) >=1:
            a, b, c = que.popleft()
            footprint[a][b] = c

            if a != 0:
                if footprint[a-1][b] == 0 and grid[a-1][b] == '.':
                    que.append([a-1, b, c+1])
            if a != H-1:
                if footprint[a+1][b] == 0 and grid[a+1][b] == '.':
                    que.append([a+1, b, c+1])
            if b != 0:
                if footprint[a][b-1] == 0 and grid[a][b-1] == '.':
                    que.append([a, b-1, c+1])
            if b != W-1:
                if footprint[a][b+1] == 0 and grid[a][b+1] == '.':
                    que.append([a, b+1, c+1])

        # print(footprint)
        return np.array(footprint).max()

    res = 0
    for i in range(H):
        for j in range(W):
            res = max(res, bfs(i,j))
    
    print(res)
        


if __name__ == "__main__":
    resolve()
