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())

grid = [[False]*(w+2) for _ in range(h+2)]
for i in range(h):
    for j in range(w):
        grid[i+1][j+1] = S[i][j] == '.'

ans = 0
 
for i in range(1,h+1):
    for j in range(1,w+1):
        if not grid[i][j]:
            continue
 
        visited = [[False for o in range(w+2)] for l in range(h+2)]
        q = deque()
        d = [[max_int for o in range(w+2)] for l in range(h+2)]
 
        visited[i][j] = True
        q.append((i,j))
        d[i][j] = 0
 
        while q:
            cy, cx = q.popleft()
            visited[cy][cx] = True
            for dy,dx in zip(y4,x4):
                ny = cy + dy
                nx = cx + dx
                if grid[ny][nx] and not visited[ny][nx]:
                    q.append((ny, nx))
                    d[ny][nx] = min(d[ny][nx], d[cy][cx] + 1)
                    ans = max(d[ny][nx], ans)
 
print(ans)