import collections as cl
def check(y,x):
    if 0 <= x and x < w and 0 <= y and y < h and s[y][x] == '.' :
        return True
    else:
        return False

def func(y,x):
    conf = [[0 for i in range(w)]for j in range(h)]
    q = cl.deque()
    count = 0
    q.append([y,x,count])
    ans = [1]
    while q:
        y,x,count= q.popleft()
        if check(y-1,x) and conf[y-1][x] == 0:
            q.append([y-1,x,count+1])
            conf[y-1][x] = 1
            ans.append(count+1)
        if check(y+1,x) and conf[y+1][x] == 0:
            q.append([y+1,x,count+1])
            conf[y+1][x] = 1
            ans.append(count+1)
        if check(y,x-1) and conf[y][x-1] == 0:
            q.append([y,x-1,count+1])
            conf[y][x-1] = 1
            ans.append(count+1)
        if check(y,x+1) and conf[y][x+1] == 0:
            q.append([y,x+1,count+1])
            conf[y][x+1] = 1
            ans.append(count+1)
    return max(ans)

h,w = map(int,input().split())
s = []
step = []
for i in range(h):
    s.append(list(map(str,input())))

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            a=func(j,i)
            step.append(a)
print(max(step))
