from collections import deque

inf = float('inf')

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

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def bfs():
    que = deque()
    d = [[inf for j in range(w)] for i in range(h)]
    que.append([sx, sy])
    d[sx][sy] = 0

    while len(que):
        p = que[0]
        que.popleft()
        if p[0] == gx and p[1] == gy:
            break

        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx and nx < h and 0 <= ny and ny < w and s[nx][ny] != '#' and d[nx][ny] == inf:
                que.append([nx, ny])
                d[nx][ny] = d[p[0]][p[1]] + 1
    
    return d[gx][gy]


ans = 0
for sx in range(h):
    for sy in range(w):
        for gx in range(h):
            for gy in range(w):
                if bfs() > ans:
                    ans = bfs()

print(ans)