# 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:]]

    head = None
    tail = None

    for y in range(h):
        for x in range(w):
            if not walls[y][x]:
                head = (x, y)
                cur, prev, count = 0, -1, 0
                while cur != prev:
                    passed = [[False]*w for _ in range(h)]
                    Q = deque([head+(0,)])
                    prev = cur
                    while Q:
                        x, y, c = Q.popleft()
                        if walls[y][x] or passed[y][x]:
                            continue

                        passed[y][x] = True
                        if count < c:
                            count = max(c, count)
                            tail = (x, y)

                        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))
                    cur = count
                    head = tail

    return str(count)


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