h,w = map(int,input().split())
C = [list(input()) for i in range(h)]

queue = []
visited = [] 
ans = 0
for i in range(h):
    T = [0]*w
    visited.append(T) 
    
for i in range(h):
    for j in range(w):
        if C[i][j] == '.':
            queue.append([i,j])
            visited[i][j] = 1

            dy_dx = [[1,0],[0,1],[-1,0],[0,-1]]

            count = 0
            p = 0
            while len(queue) > 0:
              now = queue.pop(0)
              for i in range(4):
                y = now[0]+dy_dx[i][0]
                x = now[1]+dy_dx[i][1]
                if 0 <= y < h and 0 <= x < w:
                  if C[y][x] != '#' and visited[y][x] == 0:
                    visited[y][x] = visited[now[0]][now[1]]+1
                    queue.append([y,x])
                    if p == 0:
                      count += 1
                      p += 1
              p = 0
        for i in range(h):
          for j in range(w):
            ans = max(ans,visited[i][j])
        queue = []
        visited = []  
        for i in range(h):
            T = [0]*w
            visited.append(T) 
       
            
        
print(ans-1)