unittest
{
	assert( [ "2 700", "3 500", "5 800" ].parse.expand.solve == 3 );
	assert( [ "2 2000", "3 500", "5 800" ].parse.expand.solve == 7 );
	assert( [ "2 400", "3 500", "5 800" ].parse.expand.solve == 2 );
	assert( [ "5 25000", "20 1000", "40 1000", "50 1000", "30 1000", "1 1000" ].parse.expand.solve == 66 );
}



import std.algorithm;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

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

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto dg = input.front.split.to!( long[] );

	auto upcs = new long[ 3 ][ dg[ 0 ] ];
	foreach( i, ref upc; upcs )
	{
		input.popFront;
		upc = ( ( i + 1 ) * 100 ) ~ input.front.split.to!( long[] );
	}
	
	return tuple( dg[ 1 ], upcs );
}

long solve( in long g, in long[ 3 ][] upcs )
{
	auto ts = new long[ upcs.length ];
	foreach( i, upc; upcs )
	{
		auto rc = memoize!calc( g, upc[ 0 ], upc[ 1 ], upc[ 2 ] );
		auto upcs_r = upcs[ 0 .. i ] ~ upcs[ i + 1 .. $ ];
		
		// 目標点数に達した
		if( rc[ 0 ] <= 0 )
		{
			ts[ i ] = rc[ 1 ];
			continue;
		}
		
		// 目標点数に達してないけどもう問題がないので打ち切る
		if( upcs_r.length <= 0 )
		{
			ts[ i ] = long.max;
			continue;
		}
		
		// まだ残ってる
		ts[ i ] = rc[ 1 ] + solve( rc[ 0 ], upcs_r );
	}
	
	return ts.reduce!( min );
}

auto calc( in long g, in long u, in long p, in long c )
{
	// 全問解かなくても足りる場合
	if( g <= u * ( p - 1 ) )
	{
		return tuple( 0L, cast( long ) ceil( cast( real ) g / u ) );
	}
	
	// 全問解くと足りる場合
	if( g <= u * p + c )
	{
		return tuple( 0L, cast( long ) p );
	}
	
	// 全問解いても足りない場合
	return tuple( cast( long ) g - ( u * p + c ), cast( long ) p );
}
