from collections import deque

h,w = [int(x) for x in input().split()]
m = []
for _ in range(h):
    m.append(list(input()))

def bfs(sy,sx,gy,gx):
    res = [[-1]*(w) for i in range(h)]
    res[sy][sx] = 0
    q = deque()
    q.append([sy,sx])
    while q:
        z = q.popleft()
        if z[0]==gy and z[1]==gx:
            break
        for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
            ny = z[0] + dy
            nx = z[1] + dx
            if 0<=ny<h and 0<=nx<w and m[ny][nx]=="." and res[ny][nx]==-1:
                q.append([ny,nx])
                res[ny][nx] = res[z[0]][z[1]] + 1
    return res[gy][gx]

ans = -1
for i in range(h):
    for j in range(w):
        for ii in range(h):
            for jj in range(w):
                if i==ii and j==jj:
                    continue
                if (m[i][j]=="." and m[ii][jj]=="."):
                    xxx = bfs(i,j,ii,jj)
                    if xxx != -1:
                        if xxx > ans:
                            ans = xxx
print(ans)