unittest
{
	assert( [ "101" ].solve == 4 );
	assert( [ "2" ].solve == -1 );
	assert( [ "999983" ].solve == 999982 );
}



import std.conv;
import std.range;
import std.stdio;

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

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto k = input.front.to!( long );
	
	auto ans = -1L;
	for( auto i = 0L, r = 0L; i <= k; i++ )
	{
		r = ( r + remainder!10( 7, i, k ) ) % k;
		if( r == 0 )
		{
			ans = 1 + i;
			break;
		}
	}
	return ans;
}

// ( a * B ^^ n ) % m を計算
auto remainder( long B )( long a, long n, long m )
{
	static long[][] memo;
	if( m <= 0 ) return 0L;
	if( memo.length <= m ) memo.length = m + 1;
	if( memo[ m ].length <= n )
	{
		if( memo[ m ].empty ) memo[ m ] = [ 1L % m ];
		auto i = memo[ m ].length.signed - 1;
		memo[ m ].length = n + 1;
		for( ; i < n; i++ )
		{
			memo[ m ][ i + 1 ] = ( memo[ m ][ i ] * B ) % m;
		}
	}
	return ( memo[ m ][ n ] * a ) % m;
}
