H,W = list(map(int,input().split()))
MAP = [[i for i in input()] for j in range(H)]
count = sum([l.count(".") for l in MAP])
def exaustive_search(start_h,start_w):
  determined = {(start_h,start_w):0}
  f = lambda h,w: (0<=h<H and 0<=w<W) 
  
  q = [(start_h,start_w)]
  q_idx = 0
  while count != q_idx:
    h,w = q[q_idx]
    cost = determined[(h,w)]
    for dh,dw in [(-1,0),(1,0),(0,-1),(0,1)]:
      if f(h+dh,w+dw) and (h+dh,w+dw) not in determined.keys() and MAP[h+dh][w+dw]!="#":
        determined[(h+dh,w+dw)] = cost + 1
        q.append((h+dh,w+dw))
    q_idx+=1
  return max(determined.values())


print(max([exaustive_search(h,w) for h in range(H) for w in range(W) if MAP[h][w] !="#"]))