# -*- coding: utf-8 -*-
h,w = list(map(int,input().split()))
inf=float("inf")
s = [[-1]*(w+2)] + [[-1] + [inf if i=="." else -1 for i in input()] + [-1] for _ in range(h)] + [[-1]*(w+2)]

from copy import deepcopy
from collections import deque

ret = 0
for i in range(1,h+1):
    for j in range(1,w+1):
        temp_s = deepcopy(s)
        temp_s[i][j]=-1
        stack_deque = deque([(i,j,0)])
        max_v=0
        while len(stack_deque)>0:
            hi,wj,v = stack_deque.popleft()
            v+=1
            if temp_s[hi][wj-1]!=-1:
                temp_s[hi][wj-1]=-1
                stack_deque.append([hi,wj-1,v])
                max_v=max(max_v,v)
            if temp_s[hi][wj+1]!=-1:
                temp_s[hi][wj+1]=-1
                stack_deque.append([hi,wj+1,v])
                max_v=max(max_v,v)
            if temp_s[hi-1][wj]!=-1:
                temp_s[hi-1][wj]=-1
                stack_deque.append([hi-1,wj,v])
                max_v=max(max_v,v)
            if temp_s[hi+1][wj]!=-1:
                temp_s[hi+1][wj]=-1
                stack_deque.append([hi+1,wj,v])
                max_v=max(max_v,v)
        ret=max(ret,max_v)
print(ret)