unittest
{
//	assert( [ "8 6" ].parse.expand.solve == 16 );
	assert( [ "3 3" ].parse.expand.solve == -1 );
}



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

auto solve( long x, long y )
{
	if( x == y ) return -1;
	auto ans = x;
	while( ans % y == 0 ) ans += x;
	return ans;
}
