from collections import deque
h, w = map(int, input().split())
s = []
longest = 0

for i in range(h):
    s.append(input())

ans = 0
for x in range(h):
    for y in range(w):
        q = deque()
        q.append((0, (x, y)))
        done = set()
        temp = 0

        while q:
            dis, tup = q.popleft()
            i, j = tup[0], tup[1]
            temp = max(temp, dis)

            # Right
            if j < w - 1 and s[i][j + 1] == '.':
                if str(i) + str(j + 1) not in done:
                    done.add(str(i) + str(j + 1))
                    q.append((dis + 1, (i, j + 1)))

            # Left
            if j > 0 and s[i][j - 1] == '.':
                if str(i) + str(j - 1) not in done:
                    done.add(str(i) + str(j - 1))
                    q.append((dis + 1, (i, j - 1)))

            # Up
            if i > 0 and s[i - 1][j] == '.':
                if str(i - 1) + str(j) not in done:
                    done.add(str(i - 1) + str(j))
                    q.append((dis + 1, (i - 1, j)))

            # Down
            if i < h - 1 and s[i + 1][j] == '.':
                if str(i + 1) + str(j) not in done:
                    done.add(str(i + 1) + str(j))
                    q.append((dis + 1, (i + 1, j)))

        ans = max(ans, temp)

print(ans)
