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



import std.container;
import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

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

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	input.front.formattedRead!"%s %s"( n, m );
	auto uvs = new long[ 2 ][ m ];
	foreach( ref uv; uvs )
	{
		input.popFront;
		uv = input.front.split.to!( long[] );
		uv[] -= 1;
	}
	input.popFront;
	auto s = 0L;
	auto t = 0L;
	input.front.formattedRead!"%s %s"( s, t );
	s--;
	t--;
	
	auto nss = toAdjacencyList( n, uvs );
	auto dss = bfsEx( nss, 3, s );
	return ( dss[ t ][ 0 ] == long.max ) ? -1 : dss[ t ][ 0 ];
}

// 辺配列から隣接リストを作成
auto toAdjacencyList( bool undirected = false )( long n, long[ 2 ][] es )
{
	auto nss = new long[][ n ];
	foreach( e; es )
	{
		nss[ e[ 0 ] ] ~= e[ 1 ];
		static if( undirected ) nss[ e[ 1 ] ] ~= e[ 0 ];
	}
	return nss;
}

// グラフの始点指定最短経路探索（幅優先探索）
auto bfsEx( long[][] nss, long c, long s )
{
	auto dss = new long[][]( nss.length, c );
	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 fc = queue.front[ 1 ];
		queue.removeFront();
		
		foreach( ti; nss[ fi ] )
		{
			auto tc = ( fc + 1 ) % c;
			if( dss[ ti ][ tc ] < long.max ) continue;
			
			dss[ ti ][ tc ] = dss[ fi ][ fc ] + ( tc == 0 );
			queue.insertBack( tuple( ti, tc ) );
		}
	}
	return dss;
}
