from collections import deque
h,w = map(int,input().split())
s_input = [list(input()) for i in range(h)]

mx = [0,0,1,-1]
my = [1,-1,0,0]

ans = 0
for i in range(h):
    for j in range(w):
        if s_input[i][j]=='#':
            continue
        queue = deque()
        queue.append([j,i])

        visited = [[-1]*w for i in range(h)]
        visited[i][j]=0

        res = 0
        while queue:
            y,x = queue.popleft()
            for k in range(4):
                nx = x+mx[k]
                ny = y+my[k]
                if 0<=nx<w and 0<=ny<h:
                    if visited[ny][nx]!=-1:
                        continue
                    if s_input[ny][nx]=='#':
                        continue
                    visited[ny][nx]=visited[y][x]+1
                    queue.append([nx,ny])
                    res = max(res,visited[ny][nx])
        ans = max(ans,res)
print(ans)


