h,w = map(int,input().split())
ma = []
for i in range(h):
    ma.append(list(input()))
directions = [[-1,0],[1,0],[0,-1],[0,1]]
ans = []

for j in range(h):
    for k in range(w):
        if ma[j][k] == '#':
            continue

        bfs = [[-1]*w for _ in range(h)]
        bfs[j][k] = 0
        que = [[j,k]]

        while len(que)>0:
            s,t = que.pop(0)
            for x,y in directions:
                if s+x < 0 or s+x>=h or t+y<0 or t+y>=w:
                    continue
                if ma[s+x][t+y] == '#':
                    continue
                if bfs[s+x][t+y] > 0:
                    continue
                bfs[s+x][t+y] = bfs[s][t] + 1
                que.append([s+x,t+y])
        
        tmp = 0
        for bf in bfs:
            for b in bf:
                if b>tmp:
                    tmp = b
        ans.append(tmp)
print(max(ans))
