from itertools import combinations
from collections import deque
N,M = map(int,input().split())
maze = []
for i in range(N):
    maze.append(list(input()))
INF = -1
cost = [[INF]*M for _ in range(N)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
sx,sy = 0,0
gx,gy = 0,0
ls = []
for i in range(N):
    for j in range(M):
        if maze[i][j] != "#":
            ls.append([i,j])
def bfs():
    P = deque()
    P.append([sx,sy])
    cost[sx][sy] = 0
    while len(P) != 0:
        p = P.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < N and 0 <= ny < M and maze[nx][ny] != "#" and cost[nx][ny] == INF:
                P.append([nx,ny])
                cost[nx][ny] = cost[p[0]][p[1]]+1
    return cost[gx][gy]
comb = list(combinations(list(range(len(ls))),2))
ans = 0
for i in range(len(comb)):
    cost = [[INF]*M for _ in range(N)]
    sx,sy = ls[comb[i][0]][0],ls[comb[i][0]][1]
    gx,gy = ls[comb[i][1]][0],ls[comb[i][1]][1]
    res = bfs()
    if res > ans:
        ans = res
print(ans)