import numpy as np
from collections import deque

H, W = map(int, input().split())
maze = np.array([input() for _ in range(H)])


def bfs(sty, stx):
    visited = np.array([[-1 for _ in range(W)] for _ in range(H)])
    q = deque()
    q.append((sty, stx, 0))


    def is_ok(y, x):
        if not 0 <= y <= H - 1:
            return False
        if not 0 <= x <= W - 1:
            return False
        if visited[y][x] != -1:
            return False
        if maze[y][x] == '#':
            return False
        return True


    while q:
        y, x, lv = q.popleft()
        visited[y][x] = lv
        for i in (-1, 1):
            if is_ok(y+i, x):
                q.append((y+i, x, lv+1))
            if is_ok(y, x+i):
                q.append((y, x+i, lv+1))

    return np.max(visited)

res = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == '.':
            steps = bfs(i, j)
            if steps > res:
                res = steps

print(res)
