from collections import deque
[H,W] = list(map(int,input().split()))

S = []
for i in range(H):
    S.append(list(input()))
# print('S:',*S,sep='\n')

out=[]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
#スタート・ゴール全探索
for i_s in range(H):
    for j_s in range(W):
        for i_g in range(H):
            for j_g in range(W):
                # print('S,G:',i_s,j_s,i_g,j_g)
                #BFS
                init = 10**9
                d = [[init] * W for i in range(H)]  #これを更新していく
                # print('d:',*d, sep='\n')
                que = deque([])
                que.append((i_s,j_s))
                d[i_s][j_s] = 0
                while que:
                    p = que.popleft()
                    if p[0] == i_g and p[1] == j_g:
                        break
                    for i in range(4):  #四方をチェック
                        nx = p[0] + dx[i]
                        ny = p[1] + dy[i]
                        # print('p,nx,ny,S[nx][ny]:',p,nx,ny,S[nx][ny])
                        if (0<=nx<H)and(0<=ny<W)and(S[nx][ny]!="#")and(d[nx][ny]==init):
                            # print('yahhoooo')
                            que.append((nx, ny))  #後で(nx,ny)の四方みていくよ
                            d[nx][ny] = d[p[0]][p[1]] + 1  #d更新しておくよ
                # print('d:',*d, sep='\n')
                # print('ゴール',d[i_g][j_g])
                if d[i_g][j_g]!=init:
                    out.append(d[i_g][j_g])   #ゴールの回数
# print(out)
print(max(out))
