import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
	int n = read.to!int;
	int m = read.to!int;
	
	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i);
	
	foreach(j; 0 .. m){
		int u = read.to!int - 1;
		int v = read.to!int - 1;
		nodes[u].sons ~= nodes[v];
	}
	
	int s = read.to!int - 1;
	int t = read.to!int - 1;
	Node node0 = nodes[s], node1 = nodes[t];
	
	node0.value = [0, -1, -1];
	Node[] queue = [node0];
	int ix;
	while(ix < queue.length){
		Node nd = queue[ix];
		foreach(son; nd.sons){
			bool f = 0;
			if(nd.value[0] >= 0 && son.value[1] < 0){
				son.value[1] = nd.value[0];
				f = 1;
			}
			if(nd.value[1] >= 0  && son.value[2] < 0){
				son.value[2] = nd.value[1];
				f = 1;
			}
			if(nd.value[2] >= 0  && son.value[0] < 0){
				son.value[0] = nd.value[2] + 1;
				f = 1;
			}
			if(f) queue ~= son;
		}
		log("ix:", ix, "queue:", queue, "nodes:", nodes);
		ix ++;
	}
	if(node1.value[0] >= 0) node1.value[0].writeln;
	else "-1".writeln;
}
	
class Node{ // 流用時注意
	int id;
	int[3] value = [-1, -1, -1]; // 余り0で訪れる最小の歩数 など
	Node[] sons;
	this(int id){
		this.id = id;
	}
	override string toString(){
		return (id + 1).to!string ~ "->" ~ sons.map!(x => (x.id + 1).to!string).array.join(",") ~ " " ~  value.to!string;
	}
}

