from queue import Queue

def bfs(HW, q):
    num = 0
    mem = []
    while not q.empty():
        current = q.get()
        if current[0] >= H or current[0] < 0 or current[1] >= W or current[1] < 0:
            continue
        if HW[current[0]][current[1]] == '#':
            continue

        if [current[0]+1,current[1]]  not in mem:
            mem.append([current[0]+1,current[1]])
            q.put([current[0]+1,current[1],current[2]+1])
        if [current[0],current[1]+1]  not in mem:
            mem.append([current[0],current[1]+1])
            q.put([current[0],current[1]+1,current[2]+1])
        if [current[0]-1,current[1]]  not in mem:
            mem.append([current[0]-1,current[1]])
            q.put([current[0]-1,current[1],current[2]+1])
        if [current[0],current[1]-1]  not in mem:
            mem.append([current[0],current[1]-1])
            q.put([current[0],current[1]-1,current[2]+1])
    return (current[2]-1)


H,W = map(int, input().split())

HW = [[''] * W for i in range(H)]
for i in range(H):
    h = str(input())
    for j in range(len(h)):
        HW[i][j] = h[j]

ans = 0
for si in range(H):
    for sj in range(W):
        if HW[si][sj] == '#':
            continue
        q = Queue()
        q.put([si,sj,0])
        ans = max(ans, bfs(HW, q))
print(ans)