from collections import deque
def bfs(loc):
  global ans
  d=[[float('inf')]*w for i in range(h)]
  dx=[1,0,-1,0]
  dy=[0,1,0,-1]
  que=deque([])
  que.append(loc)
  d[loc[0]][loc[1]]=0
  while que:
    p=que.popleft()
    for i in range(4):
      nx=p[0]+dx[i]
      ny=p[1]+dy[i]
      if 0<=nx<h and 0<=ny<w and maze[nx][ny]=='.' and d[nx][ny]==float('inf'):
        d[nx][ny]=d[p[0]][p[1]]+1
        que.append([nx,ny])
        if ans<d[nx][ny]:ans=d[nx][ny]
  return ans

h,w=map(int,input().split())
maze=[list(input()) for i in range(h)]
a=0
ans=0
loc=[]
for i in range(h):
  for j in range(w):
    if maze[i][j]!='#':
      loc=[i,j]
    else:continue
    a=max(a,bfs(loc))
print(a)