import queue
h,w=map(int,input().split())
maze=[]
def func(n):
    if n=="#":
        return -1
    else:
        return 0


for i in range(h):
    row=input()
    maze.append(row)
#print(maze)
root=[[-1 for i in range(h*w)] for i in range(h*w)]
for i in range(h):
    for j in range(w):
       # print(maze[i][j])
        if maze[i][j]==".":
            now=w*i+j
            hidari=w*i+j-1
            migi=w*i+j+1
            ue=w*(i-1)+j
            sita=w*(i+1)+j
            if j>0:
                if maze[i][j-1]!="#":
                    root[now][hidari]=0
            if i+1<h:
                if maze[i+1][j]!="#":
                    root[now][sita]=0
            if j+1<w:
                if maze[i][j+1]!="#":
                    root[now][migi]=0
            if 0<i:
                if maze[i-1][j]!="#":
                    root[now][ue]=0
        else:
            now=w*i+j
            now=w*i+j
            hidari=w*i+j-1
            migi=w*i+j+1
            ue=w*(i-1)+j
            sita=w*(i+1)+j
            if j>0:
                root[now][hidari]=-1
            if i+1<h:
                root[now][sita]=-1
            if j+1<w:
                root[now][migi]=-1
            if 0<i:
                root[now][ue]=-1
#print(root)
max=0
for start in range(h*w):
    dist=[-1]*(h*w)
    now=start
    dist[start]=0
    visted=[0]*(h*w)
    toVis=queue.Queue()
    visted[now]=1
    for i in range(h*w):
        if root[now][i]!=-1:
            toVis.put(i)
            dist[i]=dist[now]+1
    while toVis.empty()!=True:
        now=toVis.get()
        visted[now]=1
        for i in range(h*w):
            if root[now][i]!=-1 and visted[i]!=1:
                toVis.put(i)
                dist[i]=dist[now]+1
    #print("s:",start,"g:",goal,"len",dist[goal])
    farest=dist[now]
    if max<farest:
        max=farest
print(max)
        