import sys
import socket
import numpy
from itertools import product

hostnames = ['N551J', 'F551C', 'X553M']
input_file = 'd2.in'
if socket.gethostname() in hostnames:
    sys.stdin = open(input_file)


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    h, w = read_int_list()
    a = [read_str() for _ in range(h)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    inf = 10 ** 3
    d = numpy.full(shape=(h, w, h, w), fill_value=inf)
    for i, j in product(range(h), range(w)):
        d[i][j][i][j] = 0

    for i, j in product(range(h), range(w)):
        if a[i][j] == '#':
            continue
        for di, dj in zip(dx, dy):
            k = i + di
            l = j + dj
            if not (0 <= k < h and 0 <= l < w):
                continue
            if a[k][l] == '#':
                continue
            d[i][j][k][l] = 1

    for k, kk in product(range(h), range(w)):
        for i, ii in product(range(h), range(w)):
            for j, jj in product(range(h), range(w)):
                if d[i][ii][j][jj] > d[i][ii][k][kk] + d[k][kk][j][jj]:
                    d[i][ii][j][jj] = d[i][ii][k][kk] + d[k][kk][j][jj]


    res = 0
    for i, ii in product(range(h), range(w)):
        for j, jj in product(range(h), range(w)):
            if d[i][ii][j][jj] == inf:
                continue
            if res < d[i][ii][j][jj]:
                res = d[i][ii][j][jj]
    return int(res)


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

