h,w=map(int,input().split())
m=[input() for i in range(h)]
a=[list(map(int,m[i].replace('.','0').replace('#','1'))) for i in range(h)]
for i in range(h):
  for j in range(w):
    if a[i][j]==1:
      a[i][j]=-1

def dfs(y,x,c):
  a[y][x]=c
  tmp=[]
  for dyx in [[-1,0],[1,0],[0,-1],[0,1]]:
    ny=y+dyx[0]
    nx=x+dyx[1]
    if 0<=ny<=h-1 and 0<=nx<=w-1:
      if a[ny][nx]==0 or a[ny][nx]>c+1:
        tmp+=[[ny,nx]]
  c+=1
  for i in tmp:
    dfs(i[0],i[1],c)
  
s=[]
for i in range(h):
  for j in range(w):
    if a[i][j]!=-1:
      s+=[[i,j]]
ans=0
for k in s:
  a=[list(map(int,m[i].replace('.','0').replace('#','1'))) for i in range(h)]
  for i in range(h):
    for j in range(w):
      if a[i][j]==1:
        a[i][j]=-1
  dfs(k[0],k[1],1)
  ans=max(ans,max(map(max,a)))
print(ans-1)