from collections import deque
INF = 1e9
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]


def bfs(sy, sx, gy, gx):
    if wall[sy][sx]=="#":
        return 0
    que = deque()
    que.append((sy, sx))
    d[sy][sx] = 0
    m = 0
    while len(que) > 0:
        y, x = que.popleft()

        for i in range(4):
            ny = y+dy[i]
            nx = x+dx[i]
            if 0 <= ny and ny < h and 0 <= nx and nx < w and wall[ny][nx] != "#" and d[ny][nx] <0:
                que.append((ny, nx))
                d[ny][nx] = d[y][x]+1
    return d[gy][gx]


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

ans = 0
for i in range(h):
    for j in range(w):
        for k in range(h):
            for l in range(w):
                d = [[-1]*w for _ in range(h)]
                a = bfs(i, j, k, l)
                ans = max(ans, a)
print(ans)