import sys
import math
from math import sqrt
from collections import deque
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)

h,w=map(int,input().split())
miti=[]
for i in range(h):
    miti.append(input())
    
dist=[[-1 for i in range(w)] for j in range(h)]
dist[0][0]=0
queue=deque([])
def bfs(x,y):
    for i,j in [[x+1,y],[x,y+1],[x-1,y],[x,y-1]]:
        if i<0 or h<=i or j<0 or w<=j :continue
        if dist[i][j] != -1:continue
        if miti[i][j]=="#":continue
        dist[i][j]=dist[x][y]+1
        queue.append([i,j])
    while queue:
        t,r=queue.popleft()
        bfs(t,r)

for i in range(h):
  for j in range(w):
    if miti[i][j]==".":
      s=i;t=j
      break
  break
bfs(s,t)
dis0=0
ty=[0,0]
for i in range(h):
    for j in range(w):
        if dis0<dist[i][j]:
            dis0=dist[i][j]
            ty=[i,j]
i,j=ty
dist=[[-1 for i in range(w)] for j in range(h)]
dist[i][j]=0
queue=deque([])
bfs(i,j)

ans=0


for i in range(h):
    for j in range(w):
        if ans<dist[i][j]:
            ans=dist[i][j]

print(ans)