h,w=map(int,input().split())
s=[input() for _ in range(h)]
road = [(i,j) for i in range(h) for j in range(w) if s[i][j]=='.']

from collections import deque

dists = set()
for r in road:
  d = deque()
  d.append(r)
  dist = {r:0}
  while d:
    x,y = d.popleft()
    if s[x][y] == '#':continue
    for p in [(x,y+1),(x,y-1),(x-1,y),(x+1,y)]:
      if (0<=p[0]<h and 0<=p[1]<w) == False:continue
      if s[p[0]][p[1]] == '#': continue
      if p in dist:continue
      dist[p]=dist[(x,y)]+1
      d.append(p)
  dist_max = max([dist[v] for v in dist])
  dists.add(dist_max)
print(max(dists))    
  