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_))

  
######1回目#####
flag = set()
# キューを作成して初期ノード(root)を入れる
q = deque()
q.append(list(tree.keys())[0])
farthest = None

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

  
######2回目#####
flag = set()
# キューを作成して初期ノード(root)を入れる
q = deque()
q.append((farthest,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))

print(farthest_[1])