import copy
import sys


def walk(y, x, cost, costs):
    if not (0 <= y < len(costs) and 0 <= x < len(costs[0])):
        return -1
    if costs[y][x] != 0:
        return -1
    costs = copy.deepcopy(costs)
    costs[y][x] = cost
    max_cost = cost
    for (next_y, next_x) in [(y - 1, x), (y, x + 1), (y + 1, x), (y, x - 1)]:
        cost1 = walk(next_y, next_x, cost + 1, costs)
        if cost1 > max_cost:
            max_cost = cost1
    return max_cost


def get_costs(S):
    costs = [[0 for w in range(len(S[0]))] for h in range(len(S))]
    for h in range(len(S)):
        for w in range(len(S[0])):
            if S[h][w] == '#':
                costs[h][w] = -1
    return costs


def print_costs(costs):
    for c in costs:
        print(c)


def solve(inp):
    (H, W) = map(int, inp.readline().strip().split(' '))
    S = [list(inp.readline().strip()) for i in range(H)]

    max_cost = 0
    for start_h in range(H):
        for start_w in range(W):
            costs = get_costs(S)
            cost = walk(start_h, start_w, 1, costs)
            if cost > max_cost:
                max_cost = cost
            # print("--- cost={}".format(max_cost))
            # print_costs(costs)
            # print()

    return str(max_cost - 1)


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()
