h,w = list(map(int, input().split()))
s = []
move_time = 0
for _ in range(h):
    s.append(input())

def dfs(i, j, reccursive_time,i_map):
    if s[i][j] == "#" or i_map[i*w + j] == 1:
        return reccursive_time -1

    i_map[i*w + j] = 1
    tmp1 = 0
    tmp2 = 0
    tmp3 = 0
    tmp4 = 0

    if i != 0:
        tmp1 = dfs(i-1, j, reccursive_time+1,i_map)
    if i != h-1:
        tmp2 = dfs(i+1, j, reccursive_time+1,i_map)
    if j != 0:
        tmp3 = dfs(i, j-1, reccursive_time+1,i_map)
    if j != w-1:
        tmp4 = dfs(i-1, j, reccursive_time+1,i_map)

    return max(tmp1,tmp2,tmp3,tmp4,reccursive_time)



for i in range(h):
    for j in range(w):
        imap = [0]*w*h
        tmp = dfs(i ,j ,0 ,imap)
        if move_time < tmp:
            move_time = tmp

print(move_time)