# -*- coding: utf-8 -*-
import itertools

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

l = []
m = [input() for i in range(H)]

for h in range(H):
    for w in range(W):
        if m[h][w] == '.':
            l.append([h, w])
lc = list(itertools.combinations(l, 2))

def f(m, s, x_l, o_l):
    o_l.append([s[0], s[1]])
    #print(s)
    if s[0] != 0:
        if [s[0]-1, s[1]] not in x_l and m[s[0]-1][s[1]] == '.' and [s[0]-1, s[1]] not in o_l: #hidari
          x_l.append([s[0]-1, s[1]])
    if s[0] != H-1:
        if [s[0]+1, s[1]] not in x_l and m[s[0]+1][s[1]] == '.' and [s[0]+1, s[1]] not in o_l: #migi
         x_l.append([s[0]+1, s[1]])
    if s[1] != 0:
        if [s[0], s[1]-1] not in x_l and m[s[0]][s[1]-1] == '.' and [s[0], s[1]-1] not in o_l: #ue
            x_l.append([s[0], s[1]-1])
    if s[1] != W-1:
        if [s[0], s[1]+1] not in x_l and m[s[0]][s[1]+1] == '.' and [s[0], s[1]+1] not in o_l: #shita
            x_l.append([s[0], s[1]+1])
    return x_l

for i in range(len(lc)):
    
    s, g = list(lc[i])
   # s, g = [0, 4], [2, 0]
    #print(s,g)
    o_l = [] #もう通ったマス
    x_l = [] #いま通っているマス
    count = 1
    max_count = 0
    
    x_l = f(m, s, x_l, o_l)
    
    while True:
        
        if g in x_l and count > max_count:
            max_count = count
            #print(s, g, max_count)
            break
        for j in range(len(x_l)):
            x_l = f(m, x_l[j], x_l, o_l)
        count += 1
    #print(i)
print(max_count)
