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

nodes = {}

m.times {
	x, y = gets.chomp.split.map{|x| x.to_i}
	if nodes[x] == nil then
		nodes[x] = [y]
	else
		nodes[x] << y
	end
}

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

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

is_detected = false

tmp_zeros = {from => 0}
tmp_ones = {}
tmp_twoes = {}

while tmp_zeros.keys.size + tmp_ones.keys.size + tmp_twoes.keys.size > 0 do
	tmp_tmp_zeros = {}
	tmp_tmp_ones = {}
	tmp_tmp_twoes = {}
	

	tmp_zeros.keys.each{ |k|
		nodes[k].each{ |x|
			if ones[x] == nil then
				ones[x] = tmp_zeros[k]
				tmp_tmp_ones[x] = tmp_zeros[k]
			end
		}
	}

	tmp_ones.keys.each{ |k|
		nodes[k].each{ |x|
			if twoes[x] == nil then
				twoes[x] = tmp_ones[k]
				tmp_tmp_twoes[x] = tmp_ones[k]
			end
		}
	}

	tmp_twoes.keys.each{ |k|
		nodes[k].each{ |x|
			if zeros[x] == nil then
				zeros[x] = tmp_twoes[k] + 1
				tmp_tmp_zeros[x] = tmp_twoes[k] + 1
			end
		}
	}

	tmp_zeros = tmp_tmp_zeros
	tmp_ones = tmp_tmp_ones
	tmp_twoes = tmp_tmp_twoes

	if zeros[to] then
		puts zeros[to]
		is_detected = true
		break
	end
end

if ! is_detected then
	puts '-1'
end

STDOUT.flush
