unittest
{
	assert( [ "3 70", "20 30 10" ].parse.expand.solve == 2 );
	assert( [ "3 10", "20 30 10" ].parse.expand.solve == 1 );
	assert( [ "4 1111", "1 10 100 1000" ].parse.expand.solve == 4 );
	assert( [ "2 10", "20 20" ].parse.expand.solve == 0 );
}



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 nx = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( nx[ 1 ], as );
}

auto solve( long x, long[] as )
{
	auto ans = 0L;
	foreach( a; as.sort() )
	{
		if( a <= x )
		{
			x -= a;
			ans++;
		}
		else
		{
			x = 0;
			break;
		}
	}
	if( 0 < x ) ans--;		// 余らせてしまった場合、最後の子供に押し付けるので喜ばなくなる
	return ans;
}
