import sys
sys.setrecursionlimit(2000)
h,w = map(int,input().split())
s = []

for i in range(h):
    s.append(list(input()))

from collections import deque

def bfs(i,j,dist):
    seen[i][j] = dist
    lis = [[i-1,j],[i,j-1],[i+1,j],[i,j+1]]
    for place in lis:
        if place[0]<0 or place[0]>=h or place[1]<0 or place[1]>=w:
            continue
        if seen[place[0]][place[1]] != -1 or s[place[0]][place[1]]=="#":
            continue
        que.append([place[0],place[1],dist+1])
    if len(que):
        new = que.popleft()
        bfs(new[0],new[1],new[2])
    else:
        return


mx = 0
for i in range(h):
    for  j in range(w):
        if s[i][j]=="#":
            continue
        seen = [[-1 for _ in range(w)]for _ in range(h)]
        que = deque()
        bfs(i,j,0)
        mx = max(mx,max(max(seen)))
        #print(seen)
#print(seen)
print(mx)
