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

def main():        
    h,w=map(int,input().split())
    s=[[]*w for _ in range(h)]
    for i in range(h):
        s[i]=list(input())
    ans=0
    chk=deque()
    d=[[0,1],[0,-1],[1,0],[-1,0]]
    for i in range(h):
        for j in range(w):
            if s[i][j]=='#':
                continue
            a=[[-1]*w for _ in range(h)]
            a[i][j]=0
            chk.append([i,j])
            while chk:
                x,y=chk.popleft()
                bx,by=x,y
                for dx,dy in d:
                    x=dx+bx
                    y=dy+by
                    if x>=0 and y>=0 and x<=h-1 and y<=w-1:
                        if s[x][y]=='.' and a[x][y]==-1:
                            chk.append([x,y])
                            a[x][y]=a[bx][by]+1
                ans=max(ans,max(max(a)))
    print(ans)

if __name__ == '__main__':
    main()