n, m = gets.chomp.split.map{|x| x.to_i}

nodes = {}

m.times {
	x, y = gets.chomp.split.map{|x| x.to_i}
	nodes[[x, y]] = true
}

from, to = gets.chomp.split.map{|x| x.to_i}

zeros = {from => 0}
ones = {}
twoes = {}

orig_count = zeros.keys.size + ones.keys.size + twoes.keys.size
count = 0

while orig_count != count do
	orig_count = count

	zeros.keys.each{ |k|
		(1..n).each{ |x|
			if nodes[[k, x]] && ones[x] == nil then
				ones[x] = zeros[k]
			end
		}
	}

	ones.keys.each{ |k|
		(1..n).each{ |x|
			if nodes[[k, x]] && twoes[x] == nil then
				twoes[x] = ones[k]
			end
		}
	}

	twoes.keys.each{ |k|
		(1..n).each{ |x|
			if nodes[[k, x]] && zeros[x] == nil then
				zeros[x] = twoes[k] + 1
			end
		}
	}

	count = zeros.keys.size + ones.keys.size + twoes.keys.size
end

if zeros[to] then
	puts zeros[to]
else
	puts '-1'
end

STDOUT.flush
