n, m = map(int, input().split())
ar = []
for i in range(n):
    ar.append(list(input()))

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


def recursion(x, y, vis):
    ans = 0
    for k in range(4):
        x1 = x + dx[k]
        y1 = y + dy[k]

        if 0 <= x1 < n and 0 <= y1 < m and ar[x1][y1] == '.' and vis[x1][y1] == 0:
            vis[x1][y1] = 1
            ans = max(ans, 1 + recursion(x1, y1, vis))
    return ans


res = 0
for i in range(n):
    for j in range(m):
        if ar[i][j] == '.':
            vis = [[0] * m for k in range(n)]
            res = max(res, recursion(i, j, vis))

print(res)