from collections import deque
h,w = map(int,input().split())
s = [input() for _ in range(h)]
ans = 0

def bfs(sh,sw,gh,gw):
    dh = (1,-1,0,0)
    dw = (0,0,1,-1)
    dist = [[-1 for _ in range(w)] for _ in range(h)]
    queue = deque()
    queue.append((sh,sw))
    dist[sh][sw] = 0
    while len(queue) != 0:
        ch,cw = queue.popleft()
        for i in range(4):
            nh,nw = ch+dh[i],cw+dw[i]
            if nh == gh and nw == gw:
                return dist[ch][cw]+1
            if not (0 <= nh <= h-1 and 0 <= nw <= w-1): continue
            if s[nh][nw] == "#": continue
            if dist[nh][nw] != -1: continue
            queue.append((nh,nw))
            dist[nh][nw] = dist[ch][cw]+1

for sh in range(h):
    for sw in range(w):
        if s[sh][sw] == "#":
            continue
        for gh in range(h):
            for gw in range(w):
                if s[gh][gw] == "#":
                    continue
                ans = max(ans,bfs(sh,sw,gh,gw))

print(ans)