from collections import deque
from typing import List


def main():
    h, w = map(int, input().split())
    g = [input() for _ in range(h)]
    print(mm(h, w, g))


def mm(h: int, w: int, g: List[List[str]]) -> int:
    ret = 0
    for i in range(h):
        for j in range(w):
            if (g[i][j] == '#'):
                continue
            q = deque([(i, j, 0)])
            v = set()
            while q:
                ii, jj, cnt = q.popleft()
                v.add((ii, jj))
                ret = max(ret, cnt)
                for d_ii, d_jj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                    n_ii = ii + d_ii
                    n_jj = jj + d_jj
                    if n_ii >= h or n_jj >= w or n_ii < 0 or n_jj < 0:
                        continue
                    if g[n_ii][n_jj] == '#' or (n_ii, n_jj) in v:
                        continue
                    q.append((n_ii, n_jj, cnt + 1))
                # n_ii =
                # # ↓
                # if ii < h - 1 and g[ii + 1][jj] == '.' and (ii + 1, jj) not in v:
                #     q.append((ii + 1, jj, cnt + 1))
                # # →
                # if jj < w - 1 and g[ii][jj + 1] == '.' and (ii, jj + 1) not in v:
                #     q.append((ii, jj + 1, cnt + 1))
                # # ↑
                # if ii > 0 and g[ii - 1][jj] == '.' and (ii - 1, jj) not in v:
                #     q.append((ii - 1, jj, cnt + 1))
                # # ←
                # if jj > 0 and g[ii][jj - 1] == '.' and (ii, jj - 1) not in v:
                #     q.append((ii, jj - 1, cnt + 1))
    return ret


if __name__ == '__main__':
    main()
