def meiro(sx,sy):
    num = [[-1] * w for i in range(h)]
    num[sx][sy] = 0
    now = {(sx,sy)}
    for i in range(1,250):
        tmp = set()
        for x,y in now:
            if x > 0:
                if lis[x-1][y] == "." and num[x-1][y] == -1:
                    num[x-1][y] = i
                    tmp.add((x-1,y))
            if x < h-1:
                if lis[x+1][y] == "." and num[x+1][y] == -1:
                    num[x+1][y] = i
                    tmp.add((x+1,y))
            if y > 0:
                if lis[x][y-1] == "." and num[x][y-1] == -1:
                    num[x][y-1] = i
                    tmp.add((x,y-1))
            if y < w-1:
                if lis[x][y+1] == "." and num[x][y+1] == -1:
                    num[x][y+1] = i
                    tmp.add((x,y+1))
        now = tmp
    nu = -1
    for i in range(h):
        for j in range(w):
            if num[i][j] != -1:
                nu = max(nu,num[i][j])
    return nu

h,w = map(int,input().split())
lis = [str(input()) for i in range(h)]
ans = -1
for sx in range(h):
    for sy in range(w):
        ans = max(ans,meiro(sx,sy))
print(ans)
