H,W = map(int,input().split())
L = []
for i in range(H):
    L.append(input())
import collections
q = collections.deque()
li = ((1,0),(0,1),(-1,0),(0,-1))
LL=[]

for i in range(H):
    for j in range(W):
        visited = [[-1]*W for i in range(H)]
        if L[i][j] ==".":
            visited[i][j] = 0
            q.append((i,j))
            cnt = 0
        
        while q:
            x,y = q.popleft()
            for dx,dy in li:
                nx,ny = x+dx,y+dy
                #print(nx,ny)
                if nx<0 or nx>=H or ny<0 or ny>=W or visited[nx][ny] >0:
                    continue
                if visited[nx][ny] ==-1 and  L[nx][ny] == ".": 
                    visited[nx][ny] = visited[x][y] +1
                    cnt = max(cnt,visited[nx][ny])
                    q.append((nx,ny))
                    print(q,cnt)
        LL.append(cnt)
print(max(LL))