from collections import deque

def a():
    H,W = map(int,input().split())
    S = ["" for _ in range(H)]
    for _ in range(H):
        S[_] = input()
    b = lambda n:S[n//W][n%W] == '.'
    u = map(lambda n:(n%W,n//W),filter(b,range(H*W)))

    def bfs(root):
        depth = [[-1]*W for _ in range(H)]
        q = deque()
        q.append((root,0))
        while q:
            r,d = q.popleft()
            x,y = r
            depth[y][x] = d
            for dx,dy in ((1,0),(-1,0),(0,1),(0,-1)):
                dx += x
                dy += y
                if 0 <= dx < W and 0 <= dy < H and depth[dy][dx] == -1 and S[dy][dx] == ".":
                    q.append(((dx,dy),d+1))
        return depth
    
    p = []
    for x in map(bfs,u):
        o = []
        for y in x:
            o.append(max(y))
        p.append(max(o))
    print(max(p))


a()



