from collections import deque
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
work = [[[] for j in range(w)] for i in range(h)]
result = 0
for i in range(h):
    for j in range(w):
        if i<h-1 and s[i+1][j] == ".":
            work[i][j].append([i+1,j])
        if i>0 and s[i-1][j] == ".":
            work[i][j].append([i-1,j])
        if j<w-1 and s[i][j+1] == ".":
            work[i][j].append([i,j+1])
        if j>0 and s[i][j-1] == ".":
            work[i][j].append([i,j-1])
for i in range(h):
    for j in range(w):
        if s[i][j] != ".":
            continue
        stack = deque([[i, j]])
        temp = [[i, j]]
        distance = 0
        for k in range(h*w):
            x, y = stack.pop()
            flag = False
            for el in work[x][y]:
                if el not in temp:
                    flag = True
                    stack.append(el)
                    temp.append(el)
            if flag:
                distance += 1
            else:
                result = result if result > distance else distance
                distance = -1
            if len(stack) == 0:
                break
print(result)