#coding:utf-8
import sys

sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True

def index(a,b):
    return str(min(a,b)) + "," +  str(max(a, b))

def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    H, W = LMIIS()
    s = [[] for _ in range(H+2)]
    s[0] = "#" * (W+2)
    s[H+1] = "#" * (W+2)
    for i in range(1, H+1):
        s[i] = "#" + input() + "#"

    g = [[] for _ in range(H*W)]
    for i in range(1, H+1):
        for j in range(1, W+1):
            if s[i][j] == "#":
                g[(i-1)*W + j -1] = [-1]
            else:
                if s[i-1][j] == ".":
                    g[(i-1)*W + j -1].append((i-2)*W + j - 1)
                if s[i][j-1] == ".":
                    g[(i-1)*W + j -1].append((i-1)*W + j - 2)
                if s[i+1][j] == ".":
                    g[(i-1)*W + j -1].append(i*W + j - 1)
                if s[i][j+1] == ".":
                    g[(i-1)*W + j -1].append((i-1)*W + j)


    ans = 0
    for i in range(H*W):
        m = [-1] * (H*W)
        m[i] = 0
        q = g[i]
        l = 1
        while len(q) > 0:
            tmp = []
            for a in q:
                m[a] = l
                for b in g[a]:
                    if m[b] == -1 and not b in tmp:
                        tmp.append(b)
                    else:
                        m[b] = min(l+1, m[b])

            l += 1
            q = tmp[:]

        ans = max(ans, max(m))
    print(ans)




if __name__ == '__main__':
    main()
