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

import collections
#print(dat)
def clear_maze(sx, sy, gx, gy):
    INF = 100000000
    field_x_length = len(maze)
    field_y_length = len(maze[0])
    distance = [[INF for i in range(40)] for j in range(40)]
    def bfs():
        queue = collections.deque([])
        queue.appendleft((sx, sy))
        distance[sx][sy] = 0
        while len(queue):
            x, y = queue.pop()
            if x == gx and y == gy:
                break
            #print("seek {0} {1}".format(x, y))
            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
                if (0 <= nx and nx < field_x_length and 0 <= ny and ny < field_y_length and maze[nx][ny] != '#' and distance[nx][ny] == INF):
                    queue.appendleft((nx, ny))
                    distance[nx][ny] = distance[x][y] + 1
        return distance[gx][gy]
    return bfs()

res = -1
for yy in range(0, h):
    for xx in range(0, w):
        if maze[yy][xx] == "#":
            continue
        for yyy in range(yy, h):
            for xxx in range(0, w):
                if maze[yyy][xxx] == "#":
                    continue
                step = clear_maze(yy, xx, yyy, xxx)
                #print("s={0},{1} g={2},{3} cost = {4}".format(xx,yy,xxx,yyy,step))
                if step == 100000000:
                    continue
                res = max(res, step)
print(res)
