unittest
{
	assert( [ "3 2", "1 2", "2 3" ].parse.expand.solve == 2 );
	assert( [ "3 3", "1 2", "2 3", "2 3" ].parse.expand.solve == 1 );
	assert( [ "4 4", "1 2", "2 3", "4 1", "3 4" ].parse.expand.solve == 3 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto xys = new long[ 2 ][ nm[ 1 ] ];
	foreach( ref xy; xys )
	{
		input.popFront;
		xy = input.front.split.to!( long[] );
		xy[] -= 1;
	}
	return tuple( nm[ 0 ], xys );
}

auto solve( long n, long[ 2 ][] xys )
{
	auto cs = new long[ n ];
	auto bs = new bool[ n ];
	cs[] = 1;
	bs[ 0 ] = true;
	foreach( xy; xys )
	{
		cs[ xy[ 1 ] ]++;
		cs[ xy[ 0 ] ]--;
		if( bs[ xy[ 0 ] ]      ) bs[ xy[ 1 ] ] = true;
		if( cs[ xy[ 0 ] ] <= 0 ) bs[ xy[ 0 ] ] = false;
	}
	return bs.count( true );
}
