from collections import deque

INF = float("inf")

H,W = map(int,input().split())

N = H*W

data = ["#" * (W+2)]
for i in range(H):
  data.append("#"+input()+"#")
data.append("#" * (W+2))

offsets = [(0,1),(0,-1),(1,0),(-1,0),]

nodes = []
for i in range(1,H+1):
  for j in range(1,W+1):
    if data[i][j] == ".":
      nodes.append((i,j))

FARTHEST = 0

for start_node in nodes:
  i = start_node[0]
  j = start_node[1]
  d = [[INF]*(W+2) for i in range(H+2)]
  d[i][j] = 0
  q = deque([(i,j)])
  res = 0
  while q:
    x,y = q.popleft()
    nd = d[x][y]+1
    for o in offsets:
      nx, ny = x+o[0], y+o[1]
      if data[nx][ny] == "#":
        continue
      if nd < d[nx][ny]:
        d[nx][ny] = nd
        q.append((nx,ny))
        res = nd

print(res)