from collections import deque
h,w = map(int,input().split())
l = []
for i in range(h):
    s = list(input())
    l.append(s)
q = deque()
s = [[1,0],[0,1],[-1,0],[0,-1]]
def aaa(i,j,h,w):
    if i >= 0 and i <= h-1 and j >= 0 and j <= w-1:
        return True
    else:
        return False
ans = []
for i in range(h):
    for j in range(w):
        if l[i][j] == ".":
            rl = [[-1 for i in range(w)] for j in range(h)]
            rl[i][j] = 0
            q.append([i,j])
            while len(q) > 0:
                a,b = deque.popleft(q)
                for x in s:
                    if aaa(a+x[0],b+x[1],h,w):
                        if l[a+x[0]][b+x[1]] == ".":
                            if rl[a+x[0]][b+x[1]] > 0:
                                rl[a+x[0]][b+x[1]] = min(rl[a+x[0]][b+x[1]],rl[a][b]+1)
                            else:
                                rl[a+x[0]][b+x[1]] = rl[a][b]+1
                                q.append([a+x[0],b+x[1]])
            for y in range(h):
                ans.append(max(rl[y]))
print(max(ans))