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

def func(y,x):
    conf = set()
    q = cl.deque()
    q.append([y,x,0])
    ans = [1]
    while q:
        y,x,count= q.popleft()
        if check(y,x) == False or s[y][x] == '#' or (y,x) in conf:
            continue
        else:
            q.append([y-1,x,count+1])
            q.append([y+1,x,count+1])
            q.append([y,x-1,count+1])
            q.append([y,x+1,count+1])
            ans.append(count)
            conf.add((y,x))
    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))
