from collections import deque

x4 = [ 1,0,-1,0 ]
y4 = [ 0,1,0,-1 ] 
max_int = 2**63-1


h,w = map(int, input().split(' '))
S = []
for i in range(h):
    S.append(input())

ans = 0

for i in range(h):
    for j in range(w):
        if S[i][j] == '#':
            continue

        visited = [[False for o in range(w)] for l in range(h)]
        q = deque()
        d = [[max_int for o in range(w)] for l in range(h)]

        visited[i][j] = True
        q.append((i,j))
        d[i][j] = 0

        while(q.empty() == False):
            cy, cx = q.popleft()
            visited[cy][cx] = True
            for k in range(4):
                ny = cy + y4[k]
                nx = cx + x4[k]
                if 0 <= nx < w and 0 <= ny < h and S[ny][nx] == '.' and visited[ny][nx] == False:
                    q.append((ny, nx))
                    d[ny][nx] = min(d[ny][nx], d[cy][cx] + 1)
                    ans = max(d[ny][nx], ans)

print(ans)