from collections import deque

INF = 1000000000
h,w = map(int, input().split())
maze = [list(input()) for _ in range(h)]

def bfs(sx, sy, gx, gy):
    ds = [[1,0], [-1,0], [0,1], [0,-1]]
    visited = [[False for _ in range(h)] for _ in range(w)]
    distance = [[INF for _ in range(h)] for _ in range(w)]
    q = deque([[sx, sy]])
    distance[sx][sy] = 0

    while q:
        x, y = q.popleft()
        if visited[x][y]: continue
        visited[x][y] = True
        #print('-----', x, y)
        for dx, dy in ds:
            nx = x+dx
            ny = y+dy
            if (nx >= 0) and (nx <= w-1) and (ny >= 0) and (ny <= h-1):
                #print(nx, ny)
                if maze[ny][nx] != '#':
                    q.append([nx, ny])
                    distance[nx][ny] = min(distance[nx][ny], distance[x][y] + 1)
    return distance[gx][gy]

count = 0
for s_x in range(w):
    for s_y in range(h):
        if maze[s_y][s_x] == '.':
            for g_x in range(w):
                for g_y in range(h):
                    if (maze[g_y][g_x] == '.' and ((s_x != g_x) or (s_y != g_y))):
                        #print(s_x, s_y, g_x, g_y)
                        ans = bfs(s_x, s_y, g_x, g_y)
                        #print(ans)
                        if ans != INF and ans > count:
                            count = ans

print(count)
