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

mp = [ '' for j in range(w * h)]
j = 0

for i in range (h) :
    tmp1 = list(input())
    for j in range (w) :
        mp[w * i + j] = tmp1[j]

def bfs (k) :
    used = [False for i in range(h * w)]
    q = [k]
    used[k] = True
    depth = [0 for i in range (h * w)]

    while len(q) > 0 :
        tmp = q.pop(0)
        if tmp > w and mp[tmp - w] == '.' and used[tmp - w] == False:
            q.append (tmp - w)
            used[tmp - w] = True
            depth [tmp - w] = depth[tmp] + 1

        if tmp < (h - 1) * w and mp[tmp + w] == '.' and used[tmp + w] == False :
            q.append (tmp + w)
            used[tmp + w] = True
            depth [tmp + w] = depth[tmp] + 1

        if tmp % w != 0 and mp[tmp - 1] == '.' and used[tmp - 1] == False :
            q.append (tmp - 1)
            used[tmp - 1] = True
            depth [tmp - 1] = depth[tmp] + 1

        if (tmp + 1) % w != 0 and mp[tmp + 1] == '.'and used[tmp + 1] == False :
            q.append (tmp + 1)
            used[tmp + 1] = True
            depth [tmp + 1] = depth[tmp] + 1
    
    mx = max(depth)

    return mx

ans = 0 

for i in range (h * w) :
    if mp[i] == '.' :
        ans = max(ans , bfs(i))

print (ans)