unittest
{
	assert( [ "1 2020" ].parse.expand.solve == 0 );
	assert( [ "2020 2040" ].parse.expand.solve == 2 );
	assert( [ "4 5" ].parse.expand.solve == 20 );
	
	assert( [ "2 1999999999" ].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 lr = input.front.split.to!( long[] );
	return tuple( lr[ 0 ], lr[ 1 ] );
}

auto solve( long l, long r )
{
	auto MOD = 2019L;
	
	if( MOD < r - l ) r = l + MOD;
	
	auto ans = long.max;
	foreach( a; l .. r )
	{
		auto mf = a * ( a + 1 ) % MOD;
		ans = min( ans, mf );
		foreach( b; a + 2 .. r + 1 )
		{
			auto m = a * b % MOD;
			if( m == mf ) break;
			ans = min( ans, a * b % MOD );
		}
	}
	return ans;
}
