from collections import deque
from copy import deepcopy
def dfs(B,si,sj, H, W):
    R = [[-1]*W for _ in range(H)]
    R[si][sj] = 0
    d = deque([(si, sj)])
#    print(B)
    while d:
        x, y = d.popleft()
        t = R[x][y]
        if x > 0:
            if B[x-1][y] == 0:
                if R[x-1][y] == -1:
                    R[x-1][y] = t+1
                    d.append((x-1, y))
                elif R[x-1][y] > t+1:
                    R[x-1][y] = t+1
                    d.append((x-1,y))
        if x < H-1:
            if B[x+1][y] == 0:
                if R[x+1][y] == -1:
                    R[x+1][y] = t+1
                    d.append((x+1,y))
                elif R[x+1][y] > t+1:
                    R[x+1][y] = t+1
                d.append((x+1,y))
        if y > 0:
            if B[x][y-1] == 0:
                if R[x][y-1] == -1:
                    R[x][y-1] = t+1
                    d.append((x, y-1))
                elif R[x][y-1] > t+1:
                    R[x][y-1] = t+1
                    d.append((x,y-1))
        if y < W-1:
            if B[x][y+1] == 0:
                if R[x][y+1] == -1:
                    R[x][y+1] = t+1
                    d.append((x, y+1))
                elif R[x][y+1] > t+1:
                    R[x][y+1] = t+1
                    d.append((x,y+1))

    return max( [ max(R[i]) for i in range(H)])
    

def main():
    H, W = map( int, input().split())
    S = [ list( input()) for _ in range(H)]
    B = [[0]*W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == '#':
                B[i][j] = 1
    ans = 0
#    print(B)
    for i in range(H):
        for j in range(W):
            t = dfs(B, i, j, H, W)
            if t > ans:
                ans = t
    print(ans)
            
if __name__ == '__main__':
    main()
