from collections import deque

H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
a = 0

for h in range(H):
  for w in range(W): #スタートが(h,w)
    if S[h][w] == '#':
      continue
    d = [[-1]*W for i in range(H)]
    d[h][w] = 0
    
    q = deque([[h,w]])
    
    while q:
      nh,nw = q.pop()
      
      if nw+1<W and S[nh][nw+1]=='.' and d[nh][nw+1]==-1:
        d[nh][nw+1] = d[nh][nw]+1
        q.append([nh,nw+1])
      if 0<=nw-1 and S[nh][nw-1]=='.' and d[nh][nw-1]==-1:
        d[nh][nw-1] = d[nh][nw]+1
        q.append([nh,nw-1])
      if nh+1<H and S[nh+1][nw]=='.' and d[nh+1][nw]==-1:
        d[nh+1][nw] = d[nh][nw]+1
        q.append([nh+1,nw])
      if 0<=nh-1 and S[nh-1][nw]=='.' and d[nh-1][nw]==-1:
        d[nh-1][nw] = d[nh][nw]+1
        q.append([nh-1,nw])
    a = max(a,max([max(i) for i in d]))
    
print(a)