import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools
import heapq


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(H, W, inputs):
    INF = -1 * (10 ** 9)
    d_map = inputs
    matrix = {}
    V = []

    for sh in range(H):
        for sw in range(W):
            m = {}
            V.append((sh, sw))
            for eh in range(H):
                for ew in range(W):
                    m[(eh, ew)] = INF
            matrix[(sh, sw)] = m

    def can_pass(y, x):
        if y < 0 or x < 0 or y >= H or x >= W:
            return False
        if d_map[y][x] == '#':
            return False
        return True

    for h in range(H):
        for w in range(W):
            if not can_pass(h, w):
                continue
            if can_pass(h-1, w):
                matrix[(h-1, w)][(h, w)] = 1
                matrix[(h, w)][(h-1, w)] = 1
            if can_pass(h+1, w):
                matrix[(h+1, w)][(h, w)] = 1
                matrix[(h, w)][(h+1, w)] = 1
            if can_pass(h, w-1):
                matrix[(h, w-1)][(h, w)] = 1
                matrix[(h, w)][(h, w-1)] = 1
            if can_pass(h, w+1):
                matrix[(h, w+1)][(h, w)] = 1
                matrix[(h, w)][(h, w+1)] = 1
    # pprint(matrix)

    for mid in V:
        for start in V:
            for end in V:
                candidate = []
                if matrix[start][end] != INF:
                    candidate.append(matrix[start][end])
                if matrix[start][mid] != INF and matrix[mid][end] != INF:
                    candidate.append(matrix[start][mid] + matrix[mid][end])
                if len(candidate) > 0:
                    matrix[start][end] = min(candidate)

    max_dis = -1
    for v in V:
        max_dis = max(max_dis, max(matrix[v].values()))
    return max_dis


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [H, W] = string_to_int(input())
    ret = solve(H, W, inputs(H))
    print(ret)
