from collections import deque
h,w = map(int,input().split())
s = [input() for _ in range(h)]
ans = 0
dir = ((1,0),(0,1),(-1,0),(0,-1))

def bfs(x,y):
  dis_map = [[None if s[i][j] == '.' else -1 for j in range(w)] for i in range(h)]
  q = deque()
  dis_map[y][x] = 0
  q.append((x,y))
  while q:
    i,j = q.popleft()
    for dx,dy in dir:
      ni = i+dx
      nj = j+dy
      if 0 <= ni <= w-1 and 0 <= nj <= h-1:
        if dis_map[nj][ni] == None:
          dis_map[nj][ni] = dis_map[j][i] + 1
          q.append((ni,nj))
  ans =  max(max(dis) for dis in dis_map)
  print(dis_map,ans)
  return ans
  


for i in range (h):
  for j in range (w): #スタートの選択
    if s[i][j]=='#':continue
    dis = bfs(j,i)
    if ans < dis:
      ans = dis
print(ans)