from collections import deque
h,w = map(int,input().split())
Map = []
for i in range(h):
    tmp = list(input())
    Map.append(tmp)
ans = 0





def BFS(sy,sx,gy,gx,Map):
    visited  = [[False for i in range(w)] for j in range(h)]
    q = deque()
    q.append((sy,sx,0))
    while q:
        y,x,cnt = q.popleft()
        if y<0 or h<=y or x<0 or w<=x or visited[y][x]==True:
            continue
        if y == gy and x == gx:
            return cnt
        if Map[y][x] == '#':
            visited[y][x] = True
            continue
        if Map[y][x] == '.' :
            
            cnt += 1
            visited[y][x] = True
            q.append((y+1,x,cnt))
            q.append((y-1,x,cnt))
            q.append((y,x+1,cnt))
            q.append((y,x-1,cnt))
            
    print('------------------')
    return 0




for i in range(h):
    for j in range(w):
        #print(i,j)
        if Map[i][j] != ('.'):
            continue
        start_y = i
        start_x = j
        for x in range(h-1,-1,-1):
            for y in range(w-1,-1,-1):
                
                if Map[x][y] != ('.'):
                    continue
                goal_y = x
                goal_x = y
                ans = max(ans,BFS(start_y,start_x,goal_y,goal_x,Map))
print(ans)