# coding: utf-8
# Your code here!
import queue

H, W = map(int, input().rstrip().split())
m = [input() for _ in range(H)]

def bfs(h, w):
    q = queue.Queue()
    q.put((h, w, 0))
    f = [[False] * W for _ in range(H)]
    max_d = 0
    while q.qsize() > 0:
        h, w, d = q.get()
        f[h][w] = True
        max_d = max(max_d, d)
        for dh, dw in [[-1, 0], [1, 0], [0, 1], [0, -1]]:
            if h + dh >= 0 and h + dh < H and w + dw >= 0 and w + dw < W:
                if f[h+dh][w+dw] == False and m[h+dh][w+dw] == '.':
                    q.put((h+dh, w+dw, d+1))
    return max_d    

max_d = 0
for h in range(H):
    for w in range(W):
        if m[h][w] == '.':
            max_d = max(max_d, bfs(h, w))
        
print(max_d)
        