def count_recursive(contents_per_bag, bag_list):
    """
    Count number of nested bags from the given list

    :param contents_per_bag: per-bag mapping
    :param bag_list: list of bag to inspect
    :return: number of bags
    """

    nested_bag_qty = 0
    for bag in bag_list:
        nested_bag_qty += 1
        nested_bag_qty += count_recursive(contents_per_bag, contents_per_bag[bag])
    return nested_bag_qty