import numpy as np
import itertools

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

tbl = np.zeros([H, W], dtype=np.uint8)
for col in tbl:
	x = input().replace('.', '1').replace('#', '0')
	col[:] = list(x)

def func(start, goal):
    dp = np.ones([H, W]) * np.inf
    data = tbl.copy()
    data[start[0], start[1]] = 0
    dp[start[0], start[1]] = 0

    que = [start]

    def move(i, j, m, n):
        if m<0 or n<0 or m>=H or n>=W:
            return

        if data[m, n] == 1:
            data[m, n] = 0
            dp[m, n] = min(dp[i, j] + 1, dp[m, n])
            if [m, n] != goal:
                que.append([m, n])

    while len(que) > 0:
        i, j = que.pop(0)
        move(i,j,i-1,j)
        move(i,j,i+1,j)
        move(i,j,i,j-1)
        move(i,j,i,j+1)
       
    return dp[goal[0], goal[1]]

ans = 0
all_data = [i for i in range(H*W)]
for start, goal in itertools.combinations(all_data, 2):
    start = [start%H, start//H]
    goal = [goal%H, goal//H]
    if tbl[start[0], start[1]] == 0 or tbl[goal[0], goal[1]] == 0:
        continue
    
    num = func(start, goal)    
    if num != np.inf:
    	ans = max(ans, num)
    if ans == H + W - 2:
      	break
      
print(int(ans))