#!/usr/bin/env python3
import sys

def main():
    field_y_length,field_x_length =  map(int, input().split())
    maze = [input() for i in range(field_y_length)]

    INF = 10**8
    
    max_distance = 0

    def bfs(sx,sy,gx,gy):
        distance = [[INF for i in range(field_x_length)] for j in range(field_y_length)]
        queue = []

        queue.insert(0,(sx,sy))

        distance[sy][sx] = 0

        while len(queue):
            x,y = queue.pop()

            if x == gx and y == gy:
                break

            for i in range(0,4):
                nx,ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]

                if (0 <= nx and nx < field_x_length and 0 <= ny):
                    if (ny < field_y_length and maze[ny][nx] != '#'):
                        if (distance[ny][nx] == INF):
                            queue.insert(0, (nx, ny))
                            distance[ny][nx] = distance[y][x] + 1
        
        return distance[gy][gx]

    for sx in range(field_x_length):
        for sy in range(field_y_length):
            if maze[sy][sx] == '#':
                continue
            for gx in range(field_x_length):
                for gy in range(field_y_length):
                    if maze[gy][gx] == '#' or (gx == sx and gy == sy):
                        continue
                    max_distance = max(max_distance,bfs(sx,sy,gx,gy))
    print(max_distance)
    

if __name__ == "__main__":
    main()
