from collections import deque

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),]

tree = {}
for i in range(1,H+1):
  for j in range(1,W+1):
    if data[i][j] != ".":
      pass
    else:
      tree[(i,j)] = []
      for o in offsets:
        i_ = i+o[0]
        j_ = j+o[1]
        if data[i_][j_] == "." :
          tree[(i,j)].append((i_,j_))

nodes = list(tree.keys())
  
FARTHEST = 0

for start_node in nodes:
  flag = set()
  # キューを作成して初期ノード(root)を入れる
  q = deque()
  q.append((start_node,0))
  farthest = None

  # キューが空になるまで繰り返す
  while len(q) > 0:
      # キューの先頭（左端）からnodeを取り出す
      data = q.popleft()
      node = data[0]
      distance = data[1]
      if node is not None:
          farthest = (node,distance)
          flag.add(node)
          childs = tree[node]
          for child in childs:
            if child not in flag:
              q.append((child,distance+1))

      if FARTHEST < farthest[1]:
        FARTHEST = farthest[1]

print(FARTHEST)