from collections import deque
def farthest(yi,xi):
    q = deque([])
    q.append((yi,xi))
    dis = [[-1]*(w+2) for i in range(h+2)]
    dis[yi][xi] = 0
    while q:
        y,x = q.popleft()
        for i in range(4):
            nexty = y + dy[i]
            nextx = x + dx[i]
            if maze[nexty][nextx] == '.' and dis[nexty][nextx] == -1:
                q.append((nexty,nextx))
                dis[nexty][nextx] = dis[y][x] + 1
    return dis[y][x]
h,w = map(int,input().split())
maze = [['#'] * (w+2)]
maze += [['#']+[x for x in input()]+['#'] for _ in range(h)]
maze += [['#'] * (w+2)]
dx = [-1,0,0,1]
dy = [0,1,-1,0]
maxdis = 1
for i in range(1,h+1):
    for j in range(1,w+1):
        maxdis = max(maxdis,farthest(i,j))
print(maxdis)
