from collections import deque
import numpy as np


def bfs(maze, sx, sy):
    q = deque([(sx, sy)])
    visited = set()

    res = -1
    while q:
        res += 1

        n = len(q)
        for _ in range(n):
            x, y = q.pop()
            for dx, dy in [[1,0],[0,1],[-1,0],[0,-1]]:
                nx = x + dx
                ny = y + dy
                if nx < 0 or nx >= maze.shape[0] or ny < 0 or ny >= maze.shape[1]:
                    continue
                if (nx, ny) not in visited and maze[nx, ny] == 1:
                    q.append((nx, ny))
                    visited.add((nx, ny))
    return res


def main():
    H, W = [int(x) for x in input().split()]

    maze = np.zeros((H, W), dtype=int)

    for i in range(H):
        s = input()
        for j in range(len(s)):
            maze[i, j] = int(s[j] == ".")

    ans = 0
    for sx, sy in [(x, y) for x in range(H) for y in range(W)]:
        ans = max(ans, bfs(maze, sx, sy))
    print(ans)


if __name__ == '__main__':
    main()