from copy import deepcopy
EMP = -1 
BLOCK = -2

input_data = input().split()
h, w = map(int, input_data)

# 迷路情報
maze_map = [[EMP for i in range(w)] for j in range(h)]

# 迷路取得
for i in range(h):
    input_data = input()
    char_data = list(input_data)

    for j in range(len(char_data)):
        # 壁は-1
        if(char_data[j] == "#"):
            maze_map[i][j] = BLOCK

# 最大値取得
max_mass = 0

# 探索
for i in range(h):
    for j in range(w):

        # 迷路、キューを初期化
        tmp_maze_map = deepcopy(maze_map)
        queue_list = []

        # 自身の位置を開始位置とする
        tmp_maze_map[i][j] = 0
        # キューに自身を入れる
        queue_list.append([i,j])

        while(len(queue_list) > 0):
            get_x = queue_list[0][0]
            get_y = queue_list[0][1]

            # チェック(上) 範囲を超える、自身が壁、上が空でないのときは処理しない
            if((get_x == 0) or (tmp_maze_map[get_x][get_y] == BLOCK) or (tmp_maze_map[get_x-1][get_y] != EMP)):
                pass
            else:
                tmp_maze_map[get_x-1][get_y] = tmp_maze_map[get_x][get_y] + 1
                queue_list.append([get_x-1,get_y])

            # チェック(左)
            if((get_y == 0) or (tmp_maze_map[get_x][get_y] == BLOCK) or (tmp_maze_map[get_x][get_y-1] != EMP)):
                pass
            else:
                tmp_maze_map[get_x][get_y-1] = tmp_maze_map[get_x][get_y] + 1
                queue_list.append([get_x, get_y-1])

            # チェック(右)
            if((get_y == w-1) or (tmp_maze_map[get_x][get_y] == BLOCK) or (tmp_maze_map[get_x][get_y+1] != EMP)):
                pass
            else:
                tmp_maze_map[get_x][get_y+1] = tmp_maze_map[get_x][get_y] + 1
                queue_list.append([get_x, get_y+1])
            # チェック(下)
            if((get_x == h-1) or (tmp_maze_map[get_x][get_y] == BLOCK) or (tmp_maze_map[get_x+1][get_y] != EMP)):
                pass
            else:
                tmp_maze_map[get_x+1][get_y] = tmp_maze_map[get_x][get_y] + 1
                queue_list.append([get_x+1,get_y])

            # チェックしたマスを取り除く
            queue_list.pop(0)

        # 最大値を取得
        for k in tmp_maze_map:
            t_sum_list = deepcopy(k)
            t_sum_list += [max_mass]
            max_mass = max(t_sum_list)
            t_sum_list.clear()
        
        # 迷路リセット
        tmp_maze_map.clear()

print(max_mass)
