#!/usr/bin/perl

use v5.30;
use strict;

my %zero;
my %graph;
$; = ',';

while (<>) {
	chomp;
	my ($src, @dsts) = /(\d+)/g;
	$graph{$src} = [ @dsts ];
}


sub walk {
	my ($node) = @_;

	for my $neigh (@{ $graph{$node} }) {
		next if $zero{$neigh}++;
		walk($neigh);
	}
}

walk(0);
say scalar keys %zero;
