import copy
import sys
from collections import deque
H,W = (int(_) for _ in input().split())  
f_tmp = []
for _ in range(H):
    f_tmp.append(list(input()))
f = copy.deepcopy(f_tmp)
#dにスタート位置を入力する
d = [[1, 0], [-1, 0], [0, 1], [0, -1]]
max_root = 0
for s_i in range(H):
    for s_j in range(W):
        for g_i in range(s_i,H):
            for g_j in range(W):
                f = copy.deepcopy(f_tmp)
                q = deque()
                q.append([s_i,s_j,0])
                f[g_i][g_j] = 'g'
                flg = False
                while len(q)>0:
                    #print(f)
                    #print(q)
                    node = q.popleft()
                    if node is not None:
                        y = node[0]
                        x = node[1]
                        z = node[2]
                        f[y][x] = '#'
                        for dx, dy in d:
                            nx, ny = x + dx, y + dy
                            if not (0 <= nx < W and 0 <= ny < H) or f[ny][nx] == '#':
                                #print("NG")
                                continue
                            else:
                                tmp = [ny,nx,z+1]
                                if f[ny][nx] != 'y':
                                    q.append(tmp)
                                if f[ny][nx] == 'g' and flg == False:
                                    flg = True
                                    if max_root < z+1:
                                        max_root = z+1
                                f[ny][nx] = 'y'
print(max_root)