# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    h, w = map(int, args[0].split())
    walls = [[c == '#' for c in s] for s in args[1:]]

    count = 0
    Q = deque()

    for y in range(h):
        for x in range(w):
            if walls[y][x]:
                continue

            passed = [[False]*w for _ in range(h)]
            Q.append((x, y, 0))
            while Q:
                x, y, c = Q.popleft()
                if walls[y][x] or passed[y][x]:
                    continue

                passed[y][x] = True
                count = max(c, count)

                if 0 < x:
                    Q.append((x-1, y, c+1))
                if x+1 < w:
                    Q.append((x+1, y, c+1))
                if 0 < y:
                    Q.append((x, y-1, c+1))
                if y+1 < h:
                    Q.append((x, y+1, c+1))

    return str(count)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
