import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
from collections import *
# from heapq import *
# import functools
# import itertools
# import math
INF = 500000
mod = 10**9+7

import sys
from collections import *
INF = 500000
mod = 10**9+7

H, W = map(int, input().split())
f = [input() for i in range(H)]
es = defaultdict(lambda : INF)
for i in range(H):
    for j in range(W-1):
        if f[i][j] == '.' and f[i][j+1] == '.':
            es[(i, j, i, j+1)] = 1
            es[(i, j+1, i, j)] = 1
for i in range(H-1):
    for j in range(W):
        if f[i][j] == '.' and f[i+1][j] == '.':
            es[(i, j, i+1, j)] = 1
            es[(i+1, j, i, j)] = 1
V = []
for i in range(H):
    for j in range(W):
        if f[i][j] == '.':
            es[((i, j), (i, j))] = 0
            V.append((i, j))
for u, v in V:
    for a, b in V:
        for c, d in V:
            tmp = es[(a, b, u, v)] + es[(u, v, c, d)]
            if tmp < es[(a, b, c, d)]:
                es[(a, b, c, d)] = tmp
ans = 0
for a, b in V:
    for c, d in V:
        if ans < es[(a, b, c, d)]:
            ans = es[(a, b, c, d)]
print(ans)
