h,w = map(int,input().split())
maze = []

def mazecal(hs,ws):
    calmaze = [[0 for _ in range(w)] for _ in range(h)]
    def bfs(h1,w1,step):
        if calmaze[h1][w1] > 0 and calmaze[h1][w1] <= step:pass
        else:
            calmaze[h1][w1] = step
            if h1>0:
                if maze[h1-1][w1] == 0:
                    bfs(h1-1,w1,step+1)
            if h1<h-1:
                if maze[h1+1][w1] == 0:
                    bfs(h1+1,w1,step+1)
            if w1>0:
                if maze[h1][w1-1] == 0:
                    bfs(h1,w1-1,step+1)
            if w1<w-1:
                if maze[h1][w1+1] == 0:
                    bfs(h1,w1+1,step+1)
    bfs(hs,ws,0)
    smax = 0
    for i in range(h):smax = max(smax,max(calmaze[i]))
    return smax

for i in range(h):
    s = input()
    line = [0 if c=='.' else 1 for c in s]
    maze.append(line)

gmax = 0
for i in range(h):
    for j in range(w):
        if maze[i][j]==0:gmax = max(gmax,mazecal(i,j))
        else:pass
print(gmax)