
H, W = map(int, input().split())

maze = [[False for i in range(W)] for j in range(H)]

for h in range(H):
    ret = input()
    for i, x in enumerate(ret):
        if x == "#":
            pass
        else: # == "."
            maze[h][i] = True

def can_move(y, x, past, maze):
    if y < 0 or x < 0:
        return False
    if y >= H or x >= W:
        return False
    for yy, xx in past:
        if y == yy and x == xx:
            return False
    ret = maze[y][x]
    return ret

def past_append(past, y, x):
    flag = True
    for yy, xx in past:
        if y == yy and x == xx:
            flag = False
    if flag:
        past.append([y, x])

def bfs(maze, y, x):
    q = [[y, x]]
    r = [0]
    past = []
    max_len = 0
    while len(q) > 0:
        cur_y, cur_x = q.pop(0) # dequeue
        cur_len = r.pop(0)
        past_append(past, cur_y, cur_x)
        for dx, dy in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
            ny = cur_y + dy
            nx = cur_x + dx
            if can_move(ny, nx, past, maze):
                q.append([ny, nx])
                r.append(cur_len + 1)
            past_append(past, ny, nx)
    return cur_len

max_len = 0
for j in range(H):
    for i in range(W):
        mlen = bfs(maze, j, i)
        if max_len < mlen:
            max_len = mlen
print(max_len)
