#!/usr/bin/env python3
# Submit as pypy2


from __future__ import print_function, division, unicode_literals

__metaclass__ = type

try:
    input = raw_input
    range = xrange
except NameError:
    pass


import sys


# Test code requires python3
# from hypothesis import given
# from hypothesis import strategies as st
#
#
# def debug(*args, **kwargs):
#     print(*args, *('{}={}'.format(k, v) for k, v in kwargs.items()),
#           sep='; ', file=sys.stderr)


import itertools as it
from collections import deque


def main():
    H, W = map(int, input().split())
    S = [[x == '#' for x in input()] for _ in range(H)]
    ans = 0
    for s in it.product(range(H), range(W)):
        if S[s[0]][s[1]]:
            continue
        D = {s: 0}
        Q = deque([s])
        while Q:
            u = Q.popleft()
            for dr, dc in [(0, +1), (-1, 0), (0, -1), (+1, 0)]:
                v = (u[0] + dr, u[1] + dc)
                if not (0 <= v[0] < H and 0 <= v[1] < W) or S[v[0]][v[1]] or v in D:
                    continue
                D[v] = D[u] + 1
                ans = max(ans, D[v])
                Q.append(v)
    print(ans)


if __name__ == "__main__":
    main()
