import copy
import queue

input_int_list = list(map(int, input().split()))

H = input_int_list[0]
W = input_int_list[1]

MAX_DIST = 100000

# master_maze_list =[ [0] * H ] * W
master_maze_list = [[-1 for i in range(H+2)] for j in range(W+2)]
for vertical_i in range(H):
	input_str_H = input()
	for holizontal_i in range(W):
		if input_str_H[holizontal_i] == '#':
			master_maze_list[holizontal_i+1][vertical_i+1] = -1
		elif input_str_H[holizontal_i] == '.':
			master_maze_list[holizontal_i+1][vertical_i+1] = MAX_DIST


print(master_maze_list)


distance_max = 0

for vertical_i in range(H):
	for holizontal_i in range(W):
		search_target_maze = copy.deepcopy(master_maze_list)
		root_h = holizontal_i+1
		root_v = vertical_i+1
		distance = -1
		next_place_queue = queue.Queue()
		next_place_queue.put(root_h)
		next_place_queue.put(root_v)
		search_target_maze[root_h][root_v] = 0
		while next_place_queue.empty() != True:
			now_h = next_place_queue.get()
			now_v = next_place_queue.get()
			now_place_val = search_target_maze[now_h][now_v]

			if now_place_val == -1:
				pass
			else:
				if search_target_maze[now_h+1][now_v] > now_place_val+1:
					search_target_maze[now_h+1][now_v] = now_place_val+1
					next_place_queue.put(now_h+1)
					next_place_queue.put(now_v)

				if search_target_maze[now_h][now_v+1] > now_place_val+1:
					search_target_maze[now_h][now_v+1] = now_place_val+1
					next_place_queue.put(now_h)
					next_place_queue.put(now_v+1)

				if search_target_maze[now_h-1][now_v] > now_place_val+1:
					search_target_maze[now_h-1][now_v] = now_place_val+1
					next_place_queue.put(now_h-1)
					next_place_queue.put(now_v)

				if search_target_maze[now_h][now_v-1] > now_place_val+1:
					search_target_maze[now_h][now_v-1] = now_place_val+1
					next_place_queue.put(now_h)
					next_place_queue.put(now_v-1)
		distance_max = max(distance_max, now_place_val)
#		print(distance_max)

print(distance_max)
