from collections import deque

h,w=map(int,input().split())
maze=[input() for _ in range(h)]
dx=[1,0,-1,0]
dy=[0,1,0,-1]
res=0
for sx in range(w):
  for sy in range(h):
    if maze[sy][sx]==".":
      d=[[-1 for _ in range(w)] for _ in range(h)]
      que=deque([[sx,sy]])
      d[sy][sx]=0
      while que:
        x,y=que.popleft()
        for i in range(4):
          nx=x+dx[i]
          ny=y+dy[i]
          if 0<=nx<w and 0<=ny<h and d[ny][nx]==-1 and maze[ny][nx]==".": 
            que.append([nx,ny])
            d[ny][nx]=d[y][x]+1
            if res<d[ny][nx]:
              res=d[ny][nx] 
print(res)
