from collections import deque
d = [(-1,0),(1,0),(0,1),(0,-1)]

def bfs(y,x,c):
    q =  deque()
    q.append((y,x,c))
    ma = 0
    while q:
        y,x,c = q.popleft()
        ma = max(ma,c)
        for dy,dx in d:
            if 0<=y+dy<h and 0<=x+dx<w:
                if area[y+dy][x+dx] =="." and visit[y+dy][x+dx] == 0:
                    q.append((y+dy,x+dx,c+1))
                    visit[y+dy][x+dx] = 1
    return ma

h,w = map(int,input().split())
area = []
for i in range(h):
    area.append(list(input()))
ans = 0
for i in range(h):
    for j in range(w):
        if area[i][j] ==".":
            visit = [[0]*w for i in range(h)]
            ans = max(ans,bfs(i,j,0))
print(ans)
