n, m = map(int, input().split())
ss = []
for i in range(n):
    s = input()
    ss.append(s)


def bff(src : tuple):
    global ss
    global n, m
    d = [[1e18] * m for i in range(n)]

    # src init
    if ss[src[0]][src[1]] == '#':
        return 0

    d[src[0]][src[1]] = 0

    for itr in range(n * m):
        for i in range(n - 1, -1, -1):
            for j in range(m - 1, -1, -1):
                u = (i, j)
                if u[0] not in range(0, n) or u[1] not in range(0, m):
                    continue
                v = [(i - 1, j), (i, j - 1)]

                for vv in v:
                    if (vv[0] not in range(n) or vv[1] not in range(m)):
                        continue

                    xx = ss[vv[0]][vv[1]]
                    yy = ss[u[0]][u[1]]
                    if ss[vv[0]][vv[1]] == '#' or ss[u[0]][u[1]] == '#':
                        continue
                    if d[u[0]][u[1]] > d[vv[0]][vv[1]] + 1:
                        d[u[0]][u[1]] = d[vv[0]][vv[1]] + 1

                    if d[vv[0]][vv[1]] > d[u[0]][u[1]] + 1:
                        d[vv[0]][vv[1]] = d[u[0]][u[1]] + 1
    ans = 0
    for i in d:
        for j in i:
            if j != 1e18:
                ans = max(ans, j)
    return ans

fans = -1
for i in range(n):
    for j in range(m):

        d = bff((i, j))
        fans = max(fans, d)

print(fans)
