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

start = []
for i in range(h):
    for j in range(w):
        if s[i][j:j+1] == ".":
            start.append([i,j])
#print(start)

def meiro(ss,count):
    if len(ss) == 0 or count >= 100:
  #      for i in range(h):
  #          print(jokyo[i])
  #      print()
        global ans
        ans = max(ans,count-1)
    else:
        kouho = [[0,1],[0,-1],[1,0],[-1,0]]
        next_s = []
        for hw in ss:
            for i in range(4):    
                next_w = hw[1]+kouho[i][1]
                next_h = hw[0]+kouho[i][0]
                if next_w < w and next_w >= 0:
                    if next_h < h and next_h >= 0:
                        if s[next_h][next_w:next_w+1] == "." and jokyo[next_h][next_w] == -1:
                            next_s.append([next_h,next_w])
                            jokyo[next_h][next_w] = count + 1
        meiro(next_s,count+1)

ans = 0
for i in range(len(start)):
    jokyo = [[-1 for i in range(w)] for j in range(h)]
    jokyo[start[i][0]][start[i][1]] = 0
    meiro([start[i]],0)

print(ans)