from collections import deque
import numpy as np
h, w = map(int, input().split())
mass = [input() for _ in range(h)]

dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
ans = 0
for i in range(h):
    for j in range(w):
        visited = [[False] * w for _ in range(h)]
        depth = np.zeros((h, w))
        q = deque([[i, j]])
        while q:
            x, y = q.popleft()
            visited[x][y] = True
            for d in range(4):
                nx = x + dx[d]
                ny = y + dy[d]
                if nx < 0 or h-1 < nx:
                    continue
                if ny < 0 or w-1 < ny:
                    continue

                if mass[nx][ny] == "#":
                    continue
                if visited[nx][ny]:
                    continue

                q.append([nx, ny])
                depth[nx][ny] = depth[x][y] + 1
        ans = max(ans, np.max(depth))
print(int(ans))

