from collections import *
H,W = map(int,input().split())
S = [(W+2)*["#"]]+[["#"]+list(input())+["#"] for h in range(H)]+[(W+2)*["#"]]
D = [[1,0],[-1,0],[0,1],[0,-1]]
start = []
ans = 0

for h in range(1,H+1):
  for w in range(1,W+1):
    if S[h][w]=="." and 2<=(S[h-1][w]+S[h+1][w]+S[h][w-1]+S[h][w+1]).count("#")<=3:
      start+=[[h,w]]

for sx,sy in start:
  T = S[:]
  T[sx-1][sy-1] = 1
  Q = deque([[sx-1,sy-1]])
  while Q:
    x,y = Q.popleft()
    for dx,dy in D:
      if S[x+dx][y+dy]==".":
        S[x+dx][y+dy] = S[x][y]+1
        Q+=[[x+dx,y+dy]]
        ans = max(ans,S[x+dx][y+dy])

print(ans)