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];
	
	foreach(nd; nodes){
		bool[int] idset;
		foreach(son; nd.sons) foreach(son2; son.sons){
			idset[son2.id] = 1;
		}
		int[] ids = idset.keys;
		foreach(id; ids) nd.son2s ~= nodes[id];
	}
	
	foreach(nd; nodes){
		bool[int] idset;
		foreach(son2; nd.son2s){
			foreach(son3; son2.sons) {
				idset[son3.id] = 1;
			}
		}
		int[] ids = idset.keys;
		foreach(id; ids) nd.son3s ~= nodes[id];
	}
	
	node0.value = 0;
	node0.isVisited = 1;
	Node[] queue = [node0];
	int ix;
	while(ix < queue.length){
		Node nd = queue[ix];
		foreach(son3; nd.son3s){
			if(son3.isVisited) continue;
			son3.isVisited = 1;
			son3.value = nd.value + 1;
			queue ~= son3;
		}
		ix ++;
	}
	if(node1.isVisited) node1.value.writeln;
	else "-1".writeln;
}
	
class Node{ // 流用時注意
	int id;
	int value = -1;
	bool isVisited = 0;
	Node[] sons, son2s, son3s;
	this(int id){
		this.id = id;
	}
}

