h, w = map(int, input().split(' '))

s = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    ll = input()

    for j in range(w):
        if ll[j] == '.':
            s[i][j] = 0
        else:
            s[i][j] = 1

g = [[0 for i in range(w * h)] for j in range(w * h)]
for t in range(h * w):
    y = t // w
    x = t % w

    left = x - 1
    right = x + 1
    up = y - 1
    down = y + 1

    #print('x, y', x, y)

    if s[y][x] == 0:
        if left >= 0:
            if s[y][left] == 0:
                g[t][t - 1] = 1
                g[t - 1][t] = 1
        #print(right, w, s)
        if right < w:
            if s[y][right] == 0:
                g[t][t + 1] = 1
                g[t + 1][t] = 1
        if up >= 0:
            if s[up][x] == 0:
                g[t][t - w] = 1
                g[t - w][t] = 1
        if down < h:
            if s[down][x] == 0:
                g[t][t + w] = 1
                g[t + w][t] = 1

#print(g)

d = [[float('inf') for i in range(w * h)] for j in range(w * h)]
for i in range(w * h):
    for j in range(w * h):
        if g[i][j] != 0:
            d[i][j] = g[i][j]
        if i == j:
            d[i][j] = 0
            

for k in range(w * h):
    for i in range(w * h):
        for j in range(w * h):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]

dd = 0
for i in range(w * h):
    for j in range(w * h):
        if d[i][j] != float('inf'):
            if dd < d[i][j]:
                dd = d[i][j]
print(dd)