unittest
{
	assert( [ "4 4", "1 2", "2 3", "3 4", "4 1", "1 3" ].parse.expand.solve == 2 );
	assert( [ "3 3", "1 2", "2 3", "3 1", "1 2" ].parse.expand.solve == -1 );
	assert( [ "2 0", "1 2" ].parse.expand.solve == -1 );
	assert( [ "6 8", "1 2", "2 3", "3 4", "4 5", "5 1", "1 4", "1 5", "4 6", "1 6" ].parse.expand.solve == 2 );
}



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 nm = input.front.split.to!( long[] );
	auto uvs = new long[ 2 ][ nm[ 1 ] ];
	foreach( ref uv; uvs )
	{
		input.popFront;
		uv = input.front.split.to!( long[] );
		uv[] -= 1;
	}
	input.popFront;
	auto st = input.front.split.to!( long[] );
	st[] -= 1;
	return tuple( nm[ 0 ], uvs, st[ 0 ], st[ 1 ] );
}

auto solve( long n, long[ 2 ][] uvs, long s, long t )
{
	const M = 3;
	auto dss = bfsEx!( true )( n, M, uvs, s );
	return ( dss[ t ][ $ - 1 ] < long.max ) ? dss[ t ][ 0 ] / M : -1;
}

// 重み無しグラフの始点指定最短経路探索（幅優先探索）
// 経路長情報をmで割った余りの個数だけ持つことで1～mのタイミングで頂点に到着したかが分かる
auto bfsEx( bool directed = false )( long n, long m, long[ 2 ][] es, long s )
{
	import std.container.dlist;
	
	auto tss = new long[][ n ];
	foreach( e; es )
	{
		tss[ e[ 0 ] ] ~= e[ 1 ];
		static if( !directed ) tss[ e[ 1 ] ] ~= e[ 0 ];
	}
	
	auto dss = new long[][]( n, m );
	foreach( ref ds; dss ) ds[] = long.max;
	dss[ s ][ 0 ] = 0;
	auto queue = make!DList( tuple( s, 0L ) );
	while( !queue.empty )
	{
		auto fi = queue.front[ 0 ];
		auto fd = queue.front[ 1 ];
		queue.removeFront();
		auto td = fd + 1;
		foreach( ti; tss[ fi ] )
		{
			if( dss[ ti ][ td % m ] < long.max ) continue;
			dss[ ti ][ td % m ] = td;
			queue.insertBack( tuple( ti, td ) );
		}
	}
	return dss;
}
