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 = 0

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


print(ans)
