using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int n = nm[0];
			int m = nm[1];

			int nn = n * 3;
			var to = new List<int>[nn];
			for (int i = 0; i < nn; i++) {
				to[i] = new List<int>();
			}

			for (int i = 0; i < m; i++) {
				var uv = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				int u = uv[0] - 1;
				int v = uv[1] - 1;
				to[u * 3].Add(v * 3 + 1);
				to[u * 3 + 1].Add(v * 3 + 2);
				to[u * 3 + 2].Add(v * 3);
			}

			var st = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int s = st[0] - 1;
			int t = st[1] - 1;

			var d = new int[nn];
			for (int i = 0; i < nn; i++) {
				d[i] = int.MaxValue;
			}

			d[s * 3] = 0;

			var q = new Queue<int>();
			q.Enqueue(s * 3);
			while (q.Count > 0) {
				int cur = q.Dequeue();
				foreach (int next in to[cur]) {
					if (d[next] > d[cur] + 1) {
						d[next] = d[cur] + 1;
						q.Enqueue(next);
					}
				}
			}

			int ans = d[t * 3];
			if (ans == int.MaxValue || ans % 3 != 0) {
				Console.WriteLine(-1);
			} else {
				Console.WriteLine(ans / 3);
			}
		}
	}

	public struct ModInt
	{
		public static long Mod { get; set; } = (long)1e9 + 7;

		public static ModInt Pow(ModInt value, long k)
		{
			return Pow(value.Value, k);
		}

		public static ModInt Pow(long value, long k)
		{
			long ret = 1;
			for (k %= Mod - 1; k > 0; k >>= 1, value = value * value % Mod) {
				if ((k & 1) == 1) {
					ret = ret * value % Mod;
				}
			}
			return new ModInt(ret);
		}

		public static ModInt Inverse(ModInt value)
		{
			return Pow(value, Mod - 2);
		}

		public long Value;

		public ModInt(long value)
		{
			Value = value;
		}

		public static ModInt operator +(ModInt lhs, ModInt rhs)
		{
			lhs.Value += rhs.Value;
			if (lhs.Value >= Mod) {
				lhs.Value -= Mod;
			}
			return lhs;
		}

		public static ModInt operator -(ModInt lhs, ModInt rhs)
		{
			lhs.Value -= rhs.Value;
			if (lhs.Value < 0) {
				lhs.Value += Mod;
			}

			return lhs;
		}

		public static ModInt operator *(ModInt lhs, ModInt rhs)
		{
			return new ModInt(lhs.Value * rhs.Value % Mod);
		}
		public static ModInt operator /(ModInt lhs, ModInt rhs)
		{
			long exp = Mod - 2;
			while (exp > 0) {
				if (exp % 2 > 0) {
					lhs *= rhs;
				}

				rhs *= rhs;
				exp /= 2;
			}

			return lhs;
		}

		public static implicit operator ModInt(long n)
		{
			n %= Mod;
			if (n < 0) {
				n += Mod;
			}

			return new ModInt(n);
		}

		public override string ToString()
		{
			return Value.ToString();
		}
	}

	public static class ModCounting
	{
		private static long p_;

		private static long[] factorial_;
		private static long[] inverseFactorial_;
		private static long[] inverse_;

		public static void InitializeFactorial(long max, long p = 1000000007)
		{
			p_ = p;

			factorial_ = new long[max + 1];
			inverseFactorial_ = new long[max + 1];
			inverse_ = new long[max + 1];

			factorial_[0] = factorial_[1] = 1;
			inverseFactorial_[0] = inverseFactorial_[1] = 1;
			inverse_[1] = 1;
			for (int i = 2; i <= max; i++) {
				factorial_[i] = factorial_[i - 1] * i % p;
				inverse_[i] = p - inverse_[p % i] * (p / i) % p;
				inverseFactorial_[i] = inverseFactorial_[i - 1] * inverse_[i] % p;
			}
		}

		public static long Factorial(long n)
		{
			if (n < 0) {
				return 0;
			}

			return factorial_[n];
		}

		public static long InverseFactorial(long n)
		{
			if (n < 0) {
				return 0;
			}

			return inverseFactorial_[n];
		}

		public static long Inverse(long n)
		{
			if (n < 0) {
				return 0;
			}

			return inverse_[n];
		}

		public static long Permutation(long n, long k)
		{
			if (n < k || (n < 0 || k < 0)) {
				return 0;
			}

			return factorial_[n] * inverseFactorial_[n - k] % p_;
		}

		public static long Combination(long n, long k)
		{
			if (n < k || (n < 0 || k < 0)) {
				return 0;
			}

			return factorial_[n] * (inverseFactorial_[k] * inverseFactorial_[n - k] % p_) % p_;
		}
	}
}

Measured memory_bytes: 44384