import sys
input=sys.stdin.readline
from collections import deque

def main():
    h,w=map(int,input().split())
    MAP=[['#']*(w+2)]
    for _ in range(h):
        S=list(input().strip())
        S=['#']+S+['#']
        MAP.append(S)
    MAP.append(['#']*(w+2))
    #print(MAP)
    ans=0
    
    def Dist(k,l):
        delta=[[1,0],[0,1],[-1,0],[0,-1]]
        Dist=[[float('inf')]*(w+2) for _ in range(h+2)]
        Dist[k][l]=0
        #Visited=[[False]*(w+2) for _ in range(h+2)]
        #Visited[k][l]=True
        q=deque()
        q.append((k,l))
        while q:
            y,x=q.popleft()
            for dx,dy in delta:
                #print(y+dy,x+dx)
                if Dist[y+dy][x+dx]==float('inf') and MAP[y+dy][x+dx]=='.':
                    q.append((y+dy,x+dx))
                    Dist[y+dy][x+dx]=Dist[y][x]+1
        ret=0
        for i in range(h+2):
            for j in range(w+2):
                if Dist[i][j]==float('inf'):
                    continue
                ret=max(ret,Dist[i][j])
        return ret
        
    for i in range(1,h+1):
        for j in range(1,w+1):
            dist=Dist(i,j)
            ans=max(ans,dist)
    print(ans)
    
if __name__=='__main__':
    main()