import queue

dx = [0, 0, -1, -1]
dy = [1, -1, 0, 0]

h, w = map(int, input().split())
s = []
for i in range(h) :
    s.append(input())

ans = -1

for i in range(h) :
    for j in range(w) :
        mapple = [[100 for i in range(h)] for j in range(w)]
        q = queue.Queue()
        q.put([j,i,0])
        mapple[j][i] = 0
        cnt = 0
        while not q.empty() :
            xyc = q.get()
            cnt = max(cnt, xyc[2])
            for k in range(4) :
                x = xyc[0] + dx[k]
                y = xyc[1] + dy[k]
                #print(x, y, xyc[2])
                if y < 0 or y >= h or x < 0 or x >= w :
                    continue
                if s[y][x] == '#' :
                    continue
                if mapple[x][y] != 100 :
                    continue
                q.put([x, y, xyc[2]+1])
                mapple[x][y] = 0
                #print(x, y, xyc[2])
        ans = max(ans, cnt)


print(ans)
