h, w = map(int, input().split())
a = []
for i in range(h):
    a.extend(list(input()))

#print(*a, sep = "\n")

l = h*w
INF = 10**5

dp = [[INF]*(l) for i in range(l)]

for i in range(l):
    if a[i] == "#":
        for j in range(l):
            dp[i][j] = "#"
            dp[j][i] = "#"
            continue

    for j in range(l):
        if i == j:
            dp[i][j] = 0

    #左右上下を1にする
    #右
    if i%w+1 < w:
        dp[i][i+1] = 1
        dp[i+1][i] = 1
    #左
    if i%w-1 > 0:
        dp[i][i-1] = 1
        dp[i-1][i] = 1
    #上
    if i//h-1 > 0:
        dp[i][i-w] = 1
        dp[i-w][i] = 1
    #下
    if i//h+1 < h:
        dp[i][i+w] = 1
        dp[i+w][i] = 1

max = 0
for k in range(l):
    for i in range(l):
        for j in range(l):
            if dp[i][j] == -1:
                continue
            try:
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            except:
                dp[i][j] = dp[i][j]
max = 0
for i in dp:
    for j in i:
        try:
            if max < j:
                max = j
        except:
            pass

#print(*dp, sep="\n")
print(max)
