import queue
H, W = map(int, input().split())
S = [input() for i in range(H)]

dx = [1, 0, -1, 0]
dy = [0, -1, 0, 1]

mx = 0 

St = []

for i in range(H):
        for j in range(W):
                for k in range(H):
                        for l in range(W):
                                if i != k or j != l:
                                        if S[i][j] == "." and S[k][l] == ".":
                                                St.append([i, j, k, l]) 
print(St)

for i in St: 
        q = queue.Queue()
        checked = [[0 for j in range(W)] for i in range(H)]
        q.put([i[0], i[1]])
        flag = False
        while not q.empty():
                c = 0 
                di = q.get()    
                checked[di[0]][di[1]] = -1
                for k in range(4):
                        nh = di[0] + dy[k]
                        nx = di[1] + dx[k]
                        if 0 <= nx < W and 0 <= nh < H and checked[nh][nx] == 0:
                                if nh == i[2] and nx == i[3]:
                                        c += 1
                                        if mx < c:
                                                mx = c 
                                        flag = True
                                        break
                                elif S[nh][nx] == ".":
                                        c += 1
                                        q.put([nh, nx])
                if flag:
                        break
print(mx)