import sys

h,w = map(int,input().split())
s = [input() for i in range(h)]
do = []

mxm = 0
mmm = 0
mxcx = -1
mxcy = -1

for i in range(h):
    for j in range(w):
      if(mxcx == i and mxcy == j):
        print(mxm)
        sys.exit()
        
      if(s[i][j] == '.'):
        do.append([i,j])
        ex = [[0]*w for i in range(h)]
        ex[i][j] = 1
      else:
        continue
        
      while(len(do)!=0):
        x,y = do.pop(0)
        
        for k,l in [[1,0],[-1,0],[0,1],[0,-1]]:
          a = x+k
          b = y+l
          
          if(-1 < a < h and -1 < b < w):
            if(s[a][b] == '.' and ex[a][b] == 0):
              hantei = ex[x][y] + 1
              ex[a][b] = hantei
              o = a
              p = b
              do.append([a,b])
              
      
      for i in range(h):
        if(mmm < max(ex[i])):
          mmm = max(ex[i])
      #for i in range(h):
      #  print(ex[i])
      #print("")
      #print(hantei -1)           
        
      if(mxm < hantei - 1):
        mxm = hantei - 1
        mxcx = o
        mxcy = p
print(mxm)  