import copy
h,w = map(int,input().split())

s = [['#' for _ in range(w+2)]]
for i in range(h):
    si = ['#']
    sij = list(input())
    si.extend(sij)
    si.append('#')
    s.append(si)
s.append(['#' for _ in range(w+2)])

def bfs(i,j):
    root = copy.deepcopy(s)
    q = []
    q.append([i,j])
    root[i][j] = 0
    while q:
        ij = q.pop(0)
        i = ij[0]
        j = ij[1]
        
        if root[i-1][j] == '.': #左
            q.append([i-1,j])
            root[i-1][j] = root[i][j] + 1
        if root[i+1][j] == '.': #右
            q.append([i+1,j])
            root[i+1][j] = root[i][j] + 1
        if root[i][j+1] == '.': #上
            q.append([i,j+1])
            root[i][j+1] = root[i][j] + 1
        if root[i][j-1] == '.': #下
            q.append([i,j-1])
            root[i][j-1] = root[i][j] + 1
    max = 0
    for i in range(1,h+1):
        for j in range(1,w+1):
            if root[i][j] != '#' and root[i][j] > max:
                max = root[i][j]
    return max

ans = -1
for i in range(1,h+1):
    for j in range(1,w+1):
        k = bfs(i,j)
        if ans < k:
            ans = k
print(ans)