H,W = map(int,input().split())
S = []
for h in range(H):
    S.append(input())
from collections import deque
ans = 0
for h in range(H):
    for w in range(W):
        Q = deque([[h,w]])
        count_map = [[-1 for _ in range(W)] for __ in range(H)]
        count_map[h][w] = 0
        while Q:
            q = Q.popleft()
            cnt = count_map[q[0]][q[1]] + 1
            if q[0]-1 >= 0:#上
                if S[q[0]-1][q[1]] == "." and count_map[q[0]-1][q[1]] == -1:
                    count_map[q[0]-1][q[1]] = cnt
                    Q.append([q[0]-1,q[1]])
            if q[1]-1 >= 0:#左
                if S[q[0]][q[1]-1] == "." and count_map[q[0]][q[1]-1] == -1:
                    count_map[q[0]][q[1]-1] = cnt
                    Q.append([q[0],q[1]-1])
            if q[0]+1 <= H-1:#下
                if S[q[0]+1][q[1]] == "." and count_map[q[0]+1][q[1]] == -1:
                    count_map[q[0]+1][q[1]] = cnt
                    Q.append([q[0]+1,q[1]])
            if q[1]+1 <= W-1:#右
                if S[q[0]][q[1]+1] == "." and count_map[q[0]][q[1]+1] == -1:
                    count_map[q[0]][q[1]+1] = cnt
                    Q.append([q[0],q[1]+1])
        temp_max = 0
        for cm in count_map:
            temp_max = max(temp_max,max(cm))
        ans = max(ans,temp_max)
print(ans)
