import sys
from collections import deque
 
H,W = map(int,input().split())

town = []
visited = [[0 for i in range(W)] for j in range(H)]
 
for i in range(H): 
    c = input().strip()
    w = list(c)
    town.append(w)

def getpreStart(h,w):
    for i in range(h):
        for j in range(w):
            if town[i][j] == '.' :
                return i,j
            
def bfs(x,y) :
    q = deque()
    q.append([x,y,0])
    max_dist=0
    s=x
    t=y
    while q : #キューが空でない場合
        tx,ty,dist = q.popleft()
        if visited[ty][tx] == 0 :
            visited[ty][tx] = 1
            if town[ty][tx] == '#' :
                pass
            else :
                #周辺4マスを調べる
                for r in range (4):
                    nx = tx + dx[r]
                    ny = ty + dy[r]
                    count=0
                    if 0 <= nx < W and 0 <= ny < H and visited[ny][nx] == 0:
                        q.append([nx,ny,dist+1])
                        count+=1
                    if count==0 and dist>max_dist:
                        max_dist=dist
                        s=tx
                        t=ty
    return s,t,max_dist
                        
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
sy,sx=getpreStart(H,W)
sx,sy,max_dist=bfs(sx,sy)
visited = [[0 for i in range(W)] for j in range(H)]
sx,sy,max_dist=bfs(sx,sy)
visited = [[0 for i in range(W)] for j in range(H)]
sx,sy,max_dist=bfs(sx,sy)
print(max_dist)