n, k = map(int, raw_input().strip().split())
a = map(int, raw_input().strip().split())

d = {}
for num in a:
    try: d[(len(str(num)), num % k)] += 1
    except: d[(len(str(num)), num % k)] = 1

st = [[0 for i in xrange(11)] for j in xrange(n)]
for i in xrange(n):
    for j in xrange(11): st[i][j] = (a[i] * pow(10, j)) % k

#print d

ans = 0
for i in xrange(n):
    for j in xrange(1, 11):
        try:
            ans += d[(j, (k - (a[i] * pow(10, j))) % k)]
        except:
            ans = ans

for i in xrange(n):
    if int(str(a[i]) + str(a[i])) % k == 0: ans -= 1

print ans


n, k = map(int, raw_input().strip().split())
a = map(int, raw_input().strip().split())

d = {}
for num in a:
    try: d[(len(str(num)), num % k)] += 1
    except: d[(len(str(num)), num % k)] = 1

st = [[0 for i in xrange(11)] for j in xrange(n)]
for i in xrange(n):
    for j in xrange(11): st[i][j] = (a[i] * pow(10, j)) % k

ans = 0
for i in xrange(n):
    for j in xrange(1, 11):
        try:
            ans += d[(j, (k - (a[i] * pow(10, j))) % k)]
        except:
            ans = ans

for i in xrange(n):
    if int(str(a[i]) + str(a[i])) % k == 0: ans -= 1

print ans


rd = lambda: map(int, raw_input().split())

(n, k), a = rd(), rd()

def proceed(a):
    global n, k

    b = [{} for _ in range(11)]

    ans = 0
    for i in xrange(n - 1, 0, -1):
        cur = a[i] % k
        ln = len(str(a[i]))

        if cur not in b[ln]:
            b[ln][cur] = 0
        b[ln][cur] += 1

        for j in xrange(11):
            cur = (k - a[i - 1] * 10 ** j % k) % k
            ans += b[j][cur] if cur in b[j] else 0
    return ans

print(proceed(a) + proceed(a[::-1]))


rd = lambda: list(map(int, input().split()))

(n, k), a = rd(), rd()

def proceed(a):
    global n, k

    b = [{} for _ in range(11)]

    ans = 0
    for i in range(n - 1, 0, -1):
        cur = a[i] % k
        ln = len(str(a[i]))

        if cur not in b[ln]:
            b[ln][cur] = 0
        b[ln][cur] += 1

        for j in range(11):
            cur = (k - a[i - 1] * 10 ** j % k) % k
            ans += b[j][cur] if cur in b[j] else 0
    return ans

print(proceed(a) + proceed(a[::-1]))


rd = lambda: list(map(int, raw_input().split()))

(n, k), a = rd(), rd()

def proceed(a):
    global n, k

    b = [{} for _ in range(11)]

    ans = 0
    for i in range(n - 1, 0, -1):
        cur = a[i] % k
        ln = len(str(a[i]))

        if cur not in b[ln]:
            b[ln][cur] = 0
        b[ln][cur] += 1

        for j in range(11):
            cur = (k - a[i - 1] * 10 ** j % k) % k
            ans += b[j][cur] if cur in b[j] else 0
    return ans

print(proceed(a) + proceed(a[::-1]))


n,k=map(int,raw_input().split())
lst=map(int,raw_input().split())
from collections import *
lst2=[]
import math
def di(n):
    digits = int(math.log10(n))+1
    return digits
for i in range(0,n):
    lst2.append(((lst[i]%k),di(lst[i])))
dp=[]
for i in range(0,12):
    dp.append([])

for j in lst2:
    dp[j[1]].append(j[0])
for i in range(0,12):
    if len(dp[i])>0:
        dp[i]=Counter(dp[i])

ans=0

for i in lst:
    for j in range(2,12):
        #print i,"i"
        vl=((i%k)*pow(10,j-1))%k

        if (k-vl)%k in dp[j-1]:
            ans=ans+dp[j-1][(k-vl)%k]

for i in lst:
    if int(str(i)+str(i))%k==0 :
        ans=ans-1
print ans


n,k=map(int,raw_input().split())
lst=map(int,raw_input().split())
from collections import *
lst2=[]
import math
def di(n):
    digits = int(math.log10(n))+1
    return digits
for i in range(0,n):
    lst2.append(((lst[i]%k),di(lst[i])))
dp=[]
for i in range(0,11):
    dp.append([])

for j in lst2:
    dp[j[1]].append(j[0])
for i in range(0,11):
    if len(dp[i])>0:
        dp[i]=Counter(dp[i])

#for i in dp:
  #  print i
ans=0

for i in lst:
    for j in range(2,10):
        #print i,"i"
        vl=((i%k)*pow(10,j-1))%k

        if (k-vl)%k in dp[j-1]:
            ans=ans+dp[j-1][(k-vl)%k]

for i in lst:
    if int(str(i)+str(i))%k==0 :
        ans=ans-1
print ans


n,k=map(int,raw_input().split())
lst=map(int,raw_input().split())
from collections import *
lst2=[]
import math
def di(n):
    digits = int(math.log10(n))+1
    return digits
for i in range(0,n):
    lst2.append(((lst[i]%k),di(lst[i])))
dp=[]
for i in range(0,11):
    dp.append([])

for j in lst2:
    dp[j[1]].append(j[0])
for i in range(0,11):
    if len(dp[i])>0:
        dp[i]=Counter(dp[i])

#for i in dp:
  #  print i
ans=0

for i in lst:
    for j in range(2,11):
        #print i,"i"
        vl=((i%k)*pow(10,j-1))%k

        if (k-vl)%k in dp[j-1]:
            ans=ans+dp[j-1][(k-vl)%k]

for i in lst:
    if int(str(i)+str(i))%k==0 :
        ans=ans-1
print ans


from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write

def in_num():
    return int(raw_input())

def in_arr():
    return map(int,raw_input().split())

def pr_num(n):
    stdout.write(str(n)+'\n')

def pr_arr(arr):
    pr(' '.join(map(str,arr))+'\n')

# fast read function for total integer input

def inp():
    # this function returns whole input of
    # space/line seperated integers
    # Use Ctrl+D to flush stdin.
    return map(int,stdin.read().split())

range = xrange # not for python 3.0+

# main code
inp=inp()
n,k = inp[0],inp[1]
l=inp[2:]
d=defaultdict(Counter)

ans=0
for i in l:
    for j in range(1,11):
        d[j][(i*pow(10,j,k))%k]+=1
for i in l:
    tp=(k-(i%k))%k
    x=len(str(i))
    tp1=(i*pow(10,x,k))%k
    d[x][tp1]-=1
    ans+=d[x][tp]
    d[x][tp1]+=1
pr_num(ans)


from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write

def in_num():
    return int(raw_input())

def in_arr():
    return map(int,raw_input().split())

def pr_num(n):
    stdout.write(str(n)+'\n')

def pr_arr(arr):
    pr(' '.join(map(str,arr))+'\n')

# fast read function for total integer input

def inp():
    # this function returns whole input of
    # space/line seperated integers
    # Use Ctrl+D to flush stdin.
    return map(int,stdin.read().split())

range = xrange # not for python 3.0+

# main code

n,k = in_arr()
l=in_arr()
d=defaultdict(Counter)

ans=0
for i in l:
    for j in range(1,11):
        d[j][(i*pow(10,j,k))%k]+=1
for i in l:
    tp=(k-(i%k))%k
    x=len(str(i))
    tp1=(i*pow(10,x,k))%k
    d[x][tp1]-=1
    ans+=d[x][tp]
    d[x][tp1]+=1
pr_num(ans)


from sys import stdin
from collections import defaultdict

rints = lambda: [int(x) for x in stdin.readline().split()]
n, m = rints()
a, mem, ans = rints(), defaultdict(int), 0

for i in range(n):
    mem[a[i] % m, len(str(a[i]))] += 1

for i in range(n):
    tem = (a[i] % m, len(str(a[i])))
    mem[tem] -= 1

    for j in range(1, 11):
        a[i] *= 10
        mod = a[i] % m
        ans += mem[(m - mod) % m, j]

    mem[tem] += 1

print(ans)


from sys import stdin
from collections import defaultdict

rints = lambda: [int(x) for x in stdin.readline().split()]
n, m = rints()
a, mem, ans = rints(), defaultdict(int), 0

for i in range(n):
    mem[a[i] % m, len(str(a[i]))] += 1

for i in range(n):
    mod = a[i] % m
    tem = (mod, len(str(a[i])))
    mem[tem] -= 1

    for j in range(1, 11):
        mod = (mod * 10) % m
        ans += mem[(m - mod) % m, j]
    mem[tem] += 1

print(ans)


from sys import stdin
from collections import defaultdict

rints = lambda: [int(x) for x in stdin.readline().split()]
n, m = rints()
a, mem, ans = rints(), defaultdict(int), 0

for i in range(n):
    mem[a[i] % m, len(str(a[i]))] += 1

mem = dict(mem)
for i in range(n):
    mod = a[i] % m
    tem = (mod, len(str(a[i])))
    mem[tem] -= 1

    for j in range(1, 11):
        mod = (mod * 10) % m
        try:
            ans += mem[(m - mod) % m, j]
        except:
            continue
    mem[tem] += 1

print(ans)


import sys, math
from sys import stdin, stdout
rem = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 6+5)
#from resource import *; setrlimit(RLIMIT_STACK, (RLIM_INFINITY, RLIM_INFINITY))
take = lambda: map(int, stdin.readline().split())
from bisect import *

def digits(n):
    cnt=0
    while(n>0):
        n/=10
        cnt+=1
    return cnt
def help(arr):
    cnt =[]
    for i in range(1, 12):
        cnt.append({})
    ans = 0
    for i in arr:
        p = digits(i)
        a = i % k
        req = (k - a) % k
        #print p, cnt[p], req
        ans += cnt[p].get(req, 0)
        for j in range(1, 11):
            now = (i * pow(10, j, k)) % k
            cnt[j][now] = cnt[j].get(now, 0) + 1
    return ans

n,k=take()
arr=take()
new=[i for i in arr]
new.reverse()
print help(arr)+help(new)


import sys, math
from sys import stdin, stdout
rem = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 6+5)
#from resource import *; setrlimit(RLIMIT_STACK, (RLIM_INFINITY, RLIM_INFINITY))
take = lambda: map(int, stdin.readline().split())
from bisect import *

def digits(n):
    cnt=0
    while(n>0):
        n/=10
        cnt+=1
    return cnt
def help(arr):
    cnt = {}
    for i in range(1, 11):
        cnt[i] = {}
    ans = 0
    for i in arr:
        p = digits(i)
        a = i % k
        req = (k - a) % k
        #print p, cnt[p], req
        ans += cnt[p].get(req, 0)
        for j in range(1, 11):
            now = (i * pow(10, j, k)) % k
            cnt[j][now] = cnt[j].get(now, 0) + 1
    return ans

n,k=take()
arr=take()
new=[i for i in arr]
new.reverse()
print help(arr)+help(new)


import sys, math
from sys import stdin, stdout
rem = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 6+5)
#from resource import *; setrlimit(RLIMIT_STACK, (RLIM_INFINITY, RLIM_INFINITY))
take = lambda: map(int, stdin.readline().split())
from bisect import *

def digits(n):
    cnt=0
    while(n>0):
        n/=10
        cnt+=1
    return cnt
def help(arr):
    cnt = {}
    for i in range(1, 11):
        cnt[i] = {}
    ans = 0
    for i in arr:
        p = digits(i)
        a = i % k
        req = (k - a) % k
        if req in cnt[p]:
            ans+=cnt[p][req]
        for j in range(1, 11):
            now = (i * pow(10, j, k)) % k
            if now in cnt[j]:
                cnt[j][now]+=1
            else:
                cnt[j][now]=1
            #cnt[j][now] = cnt[j].get(now, 0) + 1
    return ans

n,k=take()
arr=take()
new=[i for i in arr]
new.reverse()
print help(arr)+help(new)


import sys, math
from sys import stdin, stdout
rem = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 6+5)
#from resource import *; setrlimit(RLIMIT_STACK, (RLIM_INFINITY, RLIM_INFINITY))
take = lambda: map(int, stdin.readline().split())
from bisect import *

def digits(n):
    cnt=0
    while(n>0):
        n/=10
        cnt+=1
    return cnt

n,k=take()
arr=take()

cnt = {}
for i in xrange(1, 10):
    cnt[i] = {}
new={}
for i in xrange(1,10):
    new[i]={}
ans = 0
for i in arr:
    p = digits(i)
    a = i % k
    req = (k - a) % k
    #print p, cnt[p], req
    ans += cnt[p].get(req, 0)
    for j in xrange(1,10):
        b=(i*pow(10,j,k))%k
        req=(k-b)%k
        ans+=new[j].get(req,0)

    for j in xrange(1, 10):
        now = (i * pow(10, j, k)) % k
        cnt[j][now] = cnt[j].get(now, 0) + 1
    new[p][a]=new[p].get(a,0)+1
print ans


import sys, math
from sys import stdin, stdout
rem = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 6+5)
#from resource import *; setrlimit(RLIMIT_STACK, (RLIM_INFINITY, RLIM_INFINITY))
take = lambda: map(int, stdin.readline().split())
from bisect import *

def digits(n):
    cnt=0
    while(n>0):
        n/=10
        cnt+=1
    return cnt
def help(arr):
    cnt = {}
    for i in xrange(1, 11):
        cnt[i] = {}
    new={}
    for i in xrange(1,11):
        new[i]={}
    ans = 0
    for i in arr:
        p = digits(i)
        a = i % k
        req = (k - a) % k
        #print p, cnt[p], req
        ans += cnt[p].get(req, 0)
        for j in xrange(1,11):
            b=(i*pow(10,j,k))%k
            req=(k-b)%k
            ans+=new[j].get(req,0)

        for j in xrange(1, 11):
            now = (i * pow(10, j, k)) % k
            cnt[j][now] = cnt[j].get(now, 0) + 1
        new[p][a]=new[p].get(a,0)+1
    return ans

n,k=take()
arr=take()
#new=[i for i in arr]
#new.reverse()
print help(arr)


import sys, math
from sys import stdin, stdout
rem = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 6+5)
#from resource import *; setrlimit(RLIMIT_STACK, (RLIM_INFINITY, RLIM_INFINITY))
take = lambda: map(int, stdin.readline().split())
from bisect import *

def digits(n):
    cnt=0
    while(n>0):
        n/=10
        cnt+=1
    return cnt
def help(arr):
    cnt = {}
    for i in xrange(1, 10):
        cnt[i] = {}
    new={}
    for i in xrange(1,10):
        new[i]={}
    ans = 0
    for i in arr:
        p = digits(i)
        a = i % k
        req = (k - a) % k
        #print p, cnt[p], req
        ans += cnt[p].get(req, 0)
        for j in xrange(1,10):
            b=(i*pow(10,j,k))%k
            req=(k-b)%k
            ans+=new[j].get(req,0)

        for j in xrange(1, 10):
            now = (i * pow(10, j, k)) % k
            cnt[j][now] = cnt[j].get(now, 0) + 1
        new[p][a]=new[p].get(a,0)+1
    return ans

n,k=take()
arr=take()
#new=[i for i in arr]
#new.reverse()
print help(arr)


import sys, math
from sys import stdin, stdout
rem = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 6+5)
#from resource import *; setrlimit(RLIMIT_STACK, (RLIM_INFINITY, RLIM_INFINITY))
take = lambda: map(int, stdin.readline().split())
from bisect import *

def digits(n):
    cnt=0
    while(n>0):
        n/=10
        cnt+=1
    return cnt
def help(arr):
    cnt = {}
    for i in xrange(1, 11):
        cnt[i] = {}
    for i in arr:
        p=digits(i)
        a=i%k
        if a in cnt[p]:
            cnt[p][a]+=1
        else:
            cnt[p][a]=1
        #cnt[p][a]=cnt[p].get(a,0)+1
    ans = 0
    for i in arr:
        for j in xrange(1,11):
            num=(i*pow(10,j,k))%k
            req=(k-num)%k
            if req in cnt[j]:
                ans+=cnt[j][req]
            #ans+=cnt[j].get(req,0)
            if digits(i)==j and i%k==req:
                ans-=1

    return ans

n,k=take()
arr=take()
new=[i for i in arr]
new.reverse()
print help(arr)


import sys, math
from sys import stdin, stdout
rem = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 6+5)
#from resource import *; setrlimit(RLIMIT_STACK, (RLIM_INFINITY, RLIM_INFINITY))
take = lambda: map(int, stdin.readline().split())
from bisect import *

def digits(n):
    cnt=0
    while(n>0):
        n/=10
        cnt+=1
    return cnt
def help(arr):
    cnt = {}
    for i in range(1, 11):
        cnt[i] = {}
    for i in arr:
        p=digits(i)
        a=i%k
        cnt[p][a]=cnt[p].get(a,0)+1
    ans = 0
    for i in arr:
        for j in range(1,11):
            num=(i*pow(10,j,k))%k
            req=(k-num)%k
            ans+=cnt[j].get(req,0)
            if digits(i)==j and i%k==req:
                ans-=1

    return ans

n,k=take()
arr=take()
new=[i for i in arr]
new.reverse()
print help(arr)


#v
n, k = map(int, raw_input().split())
a = map(int, raw_input().split())

d = {}
for i in xrange(len(a)):
    key = (len(str(a[i])), a[i] % k)
    if key in d: d[key] += 1
    else: d[key] = 1

ans = -sum([1 if int(str(a[i]) + str(a[i])) % k == 0 else 0 for i in xrange(n)])

for i in xrange(n):
    for j in xrange(1, 11):
        key = (j, (k - (a[i] * pow(10, j))) % k)
        if key in d: ans += d[key]

print ans


n, k = map(int, raw_input().strip().split())
a = map(int, raw_input().strip().split())

d = {}
for num in a:
    try: d[(len(str(num)), num % k)] += 1
    except: d[(len(str(num)), num % k)] = 1

st = [[0 for i in xrange(11)] for j in xrange(n)]
for i in xrange(n):
    for j in xrange(11): st[i][j] = (a[i] * pow(10, j)) % k

ans = 0
for i in xrange(n):
    for j in xrange(1, 11):
        try:
            ans += d[(j, (k - (a[i] * pow(10, j))) % k)]
        except:
            ans = ans

for i in xrange(n):
    if int(str(a[i]) + str(a[i])) % k == 0: ans -= 1

print ans


def main():
    n, k = map(int, raw_input().split())
    aa, cnt, res = [], {}, 0
    scale = [10 ** i + 1 for i in xrange(11)]
    for w in raw_input().split():
        a, s = int(w), len(w)
        aa.append(a)
        if not a * scale[s] % k:
            res -= 1
        t = (s, a % k)
        cnt[t] = cnt.get(t, 0) + 1
    scale = [1 - i for i in scale]
    for a in aa:
        for s in xrange(1, 11):
            x = a * scale[s] % k
            res += cnt.get((s, x), 0)
    print(res)

if __name__ == '__main__':
    main()


def main():
    n, k = map(int, raw_input().split())
    aa, cnt, res = [], {}, 0
    scale = [10 ** i + 1 for i in xrange(10)]
    for w in raw_input().split():
        a, s = int(w), len(w)
        aa.append(a)
        if not a * scale[s] % k:
            res -= 1
        t = (s, a % k)
        cnt[t] = cnt.get(t, 0) + 1
    scale = [1 - i for i in scale]
    for a in aa:
        for s in xrange(1, 10):
            x = a * scale[s] % k
            res += cnt.get((s, x), 0)
    print(res)

if __name__ == '__main__':
    main()


def main():
    n, k = map(int, raw_input().split())
    aa, cnt, res = [], {}, 0
    scale = [10 ** i + 1 for i in xrange(10)]
    for w in raw_input().split():
        a, s = int(w), len(w)
        aa.append(a)
        if not a * scale[s] % k:
            res -= 1
        t = (s, a % k)
        cnt[t] = cnt.get(t, 0) + 1
    scale = [1 - i for i in scale]
    for a in aa:
        for s in xrange(1, 11):
            x = a * scale[s] % k
            res += cnt.get((s, x), 0)
    print(res)

if __name__ == '__main__':
    main()


n, k = map(int, raw_input().split())
a = map(int, raw_input().split())

d = {}
for i in xrange(len(a)):
    key = (len(str(a[i])), a[i] % k)
    if key in d: d[key] += 1
    else: d[key] = 1

pw10 = {}
for i in xrange(n):
    for j in xrange(11): pw10[(i, j)] = (a[i] * (10**j)) % k

ans = -sum([1 if int(str(a[i]) + str(a[i])) % k == 0 else 0])
for i in xrange(n):
    for j in xrange(1, 11):
        key = (j, (k - pw10[i, j]))
        if key in d: ans += 1

print ans


n, k = map(int, raw_input().split())
a = map(int, raw_input().split())

d = {}
for i in xrange(len(a)):
    key = (len(str(a[i])), a[i] % k)
    if key in d: d[key] += 1
    else: d[key] = 1

ans = -sum([1 if int(str(a[i]) + str(a[i])) % k == 0 else 0 for i in xrange(n)])

for i in xrange(n):
    for j in xrange(1, 11):
        key = (j, (k - (a[i] * pow(10, j))) % k)
        if key in d: ans += d[key]

print ans


cnt = [dict() for _ in range(11)]

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())

for it in a:
  ln = len(str(it))
  curr = it % k
  cnt[ln][curr] = cnt[ln].get(curr, 0) + 1

rs = 0
for it in a:
  for i in range(1, 11):
    curr = it * (10 ** i) % k
    rs += cnt[i].get((k - curr) % k, 0)
    if len(str(it)) == i and it % k == (k - curr) % k:
      rs -= 1

print rs


#coding:utf-8

maxn = 200005

mp = [{} for i in range (11)]
n, k = map (int, raw_input().split ())
a = map (int, raw_input().split ())

ans = long (0)
for num in a:
	p = len (str (num))
	cur = num%k
	mp[p][cur] = mp[p].get (cur, 0)+1
	num = int (str (num)*2)
	ans -= 1 if num%k == 0 else 0

for i in range (1, 11):
	for j in a:
		more = long(10)**i * j % k
		#print more
		need = (k-more)%k
		ans += mp[i].get (need, 0)
print ans


'''input
6 11
45 1 10 12 11 7
'''
import sys
from collections import defaultdict
n,k = map(int,sys.stdin.readline().split())
arr = map(int,sys.stdin.readline().split())

rem = [defaultdict(int) for i in range(11)]
for i in range(n):
	rem[len(str(arr[i]))][arr[i]%k] += 1
ans = 0
zzz = [10**j for j in range(11)]
for i in range(n):
	for j in range(11):
		zz = (arr[i]*zzz[j])%k
		rzz = (k-zz)%k
		ans += rem[j][rzz]
		if (len(str(arr[i]))) == j and ((arr[i]+arr[i]*zzz[j])%k == 0):
			ans -= 1
print ans


'''input
6 11
45 1 10 12 11 7
'''
import sys
from collections import defaultdict
n,k = map(int,sys.stdin.readline().split())
arr = map(int,sys.stdin.readline().split())

rem = [defaultdict(int) for i in range(11)]
for i in range(n):
	rem[len(str(arr[i]))][arr[i]%k] += 1
ans = 0
zzz = [10**j for j in range(11)]
for i in range(n):
	for j in range(1,11):
		zz = (arr[i]*zzz[j])%k
		rzz = (k-zz)%k
		ans += rem[j][rzz]
		if (len(str(arr[i]))) == j and ((arr[i]%k+zz)%k == 0):
			ans -= 1
print ans


'''input
6 11
45 1 10 12 11 7
'''
import sys
from collections import defaultdict
n,k = map(int,sys.stdin.readline().split())
arr = map(int,sys.stdin.readline().split())

rem = [defaultdict(int) for i in range(11)]
for i in range(n):
	q = len(str(arr[i]))
	qq = arr[i]%k
	rem[q][qq] = rem[q].get(qq,0)+1
ans = 0
zzz = [10**j for j in range(11)]
for i in range(n):
	for j in range(1,11):
		zz = (arr[i]*zzz[j])%k
		rzz = (k-zz)%k
		ans += rem[j].get(rzz,0)
		if (len(str(arr[i]))) == j and ((arr[i]%k+zz)%k == 0):
			ans -= 1
print ans


'''input
6 11
45 1 10 12 11 7
'''
def binarySearch(arr, l, r, x):
    if (r < l):
        return -1

    mid = int( l + (r - l) / 2)

    # If the element is present
    # at the middle itself
    if arr[mid] == x:
        return mid

    # If element is smaller than
    # mid, then it can only be
    # present in left subarray
    if arr[mid] > x:
        return binarySearch(arr, l,
                            mid - 1, x)

    # Else the element
    # can only be present
    # in right subarray
    return binarySearch(arr, mid + 1,
                                r, x)

# Returns number of times
# x occurs in arr[0..n-1]
def countOccurrences(arr, n, x):
    ind = binarySearch(arr, 0, n - 1, x)

    # If element is not present
    if ind == -1:
        return 0

    # Count elements
    # on left side.
    count = 1
    left = ind - 1
    while (left >= 0 and
           arr[left] == x):
        count += 1
        left -= 1

    # Count elements on
    # right side.
    right = ind + 1;
    while (right < n and
           arr[right] == x):
        count += 1
        right += 1

    return count
import sys
n,k = map(int,sys.stdin.readline().split())
arr = map(int,sys.stdin.readline().split())
rem = [[] for i in range(11)]
for i in range(n):
	rem[len(str(arr[i]))].append(arr[i]%k)
for i in range(11):
	rem[i].sort()
ans = 0
for i in range(n):
	for j in range(11):
		zz = (arr[i]*(10**j))%k
		rzz = (k-zz)%k
		ans += countOccurrences(rem[j],len(rem[j]),rzz)
		if (len(str(arr[i]))) == j and ((arr[i]+arr[i]*(10**j))%k == 0):
			ans -= 1
print ans


'''input
6 11
45 1 10 12 11 7
'''
def binarySearch(arr, l, r, x):
    if (r < l):
        return -1

    mid = int( l + (r - l) / 2)

    # If the element is present
    # at the middle itself
    if arr[mid] == x:
        return mid

    # If element is smaller than
    # mid, then it can only be
    # present in left subarray
    if arr[mid] > x:
        return binarySearch(arr, l,
                            mid - 1, x)

    # Else the element
    # can only be present
    # in right subarray
    return binarySearch(arr, mid + 1,
                                r, x)

# Returns number of times
# x occurs in arr[0..n-1]
def countOccurrences(arr, n, x):
    ind = binarySearch(arr, 0, n - 1, x)

    # If element is not present
    if ind == -1:
        return 0

    # Count elements
    # on left side.
    count = 1
    left = ind - 1
    while (left >= 0 and
           arr[left] == x):
        count += 1
        left -= 1

    # Count elements on
    # right side.
    right = ind + 1;
    while (right < n and
           arr[right] == x):
        count += 1
        right += 1

    return count
import sys
from collections import defaultdict
n,k = map(int,sys.stdin.readline().split())
arr = map(int,sys.stdin.readline().split())

rem = [defaultdict(int) for i in range(11)]
for i in range(n):
	rem[len(str(arr[i]))][arr[i]%k] += 1
ans = 0
for i in range(n):
	for j in range(11):
		zz = (arr[i]*(10**j))%k
		rzz = (k-zz)%k
		ans += rem[j][rzz]
		if (len(str(arr[i]))) == j and ((arr[i]+arr[i]*(10**j))%k == 0):
			ans -= 1
print ans


'''input
6 11
45 1 10 12 11 7
'''
import sys
from collections import defaultdict
n,k = map(int,sys.stdin.readline().split())
arr = map(int,sys.stdin.readline().split())

rem = [defaultdict(int) for i in range(11)]
for i in range(n):
	rem[len(str(arr[i]))][arr[i]%k] += 1
ans = 0
zzz = [10**j for j in range(11)]
for i in range(n):
	for j in range(11):
		zz = (arr[i]*zzz[j])%k
		rzz = (k-zz)%k
		ans += rem[j][rzz]
		if (len(str(arr[i]))) == j and ((arr[i]+arr[i]*(10**j))%k == 0):
			ans -= 1
print ans


n,m=map(int,input().split())
arr=list(map(int,input().split()))
cnt=[0]*200002
ext=0
for i in range(n):
    if arr[i]%m==0:
        ext+=1
    cnt[arr[i]]+=1
ans=0
for i in range(n):
    cnt[arr[i]]-=1
    rem=arr[i]%m
   # print("********",rem,"********")

    if rem==0:
        ans+=(ext-1)
    else:
        mul=10
        while(mul<=100000):
            st=rem*mul
            #print("___________",st)
            rr=mul//10
            st+=rr
            j=m-st%m
            if j==m:
                rr=mul//10
            else:
                rr=mul//10+j
            while(rr%mul==rr%(mul*10)):
               # print(rr)
                if cnt[rr]>0:
                    ans+=1
                rr+=m
            mul*=10
    cnt[arr[i]]+=1
print(ans)


n,m=map(int,input().split())
arr=list(map(int,input().split()))
cnt=[0]*10
for i in range(10):
    cnt[i]={}
for i in range(n):
    t=arr[i]
    l=0
    while(t>0):
        t=t//10
        l+=1
    key=arr[i]%m
    if key in cnt[l]:
        cnt[l][key]+=1
    else:
        cnt[l][key]=1
ans=0
for i in range(n):
    t=arr[i]
    l=0
    while(t>0):
        t=t//10
        l+=1
    ky=arr[i]%m
    cnt[l][ky]-=1
    mul=10
    c=1
    while c<=9:
        key=(m-(mul*arr[i])%m)%m
       # print(key,c,arr[i]*mul)
        if key in cnt[c]:
           # print("*",cnt[c][key])
            ans+=cnt[c][key]
        c+=1
        mul*=10
    cnt[l][ky]+=1
print(ans)


n,m=map(int,input().split())
arr=list(map(int,input().split()))
cnt=[0]*12
for i in range(12):
    cnt[i]={}
for i in range(n):
    t=arr[i]
    l=0
    while(t>0):
        t=t//10
        l+=1
    key=arr[i]%m
    if key in cnt[l]:
        cnt[l][key]+=1
    else:
        cnt[l][key]=1
ans=0
for i in range(n):
    t=arr[i]
    l=0
    while(t>0):
        t=t//10
        l+=1
    ky=arr[i]%m
    cnt[l][ky]-=1
    mul=10
    c=1
    while c<=11:
        key=(m-(mul*arr[i])%m)%m
       # print(key,c,arr[i]*mul)
        if key in cnt[c]:
           # print("*",cnt[c][key])
            ans+=cnt[c][key]
        c+=1
        mul*=10
    cnt[l][ky]+=1
print(ans)


n,m=map(int,input().split())
arr=list(map(int,input().split()))
# arr.sort()
# print(arr)
cnt=[0]*200002
ext=0
for i in range(n):
    if arr[i]%m==0:
        ext+=1
    cnt[arr[i]]+=1
ans=0
for i in range(n):
    cnt[arr[i]]-=1
    rem=arr[i]%m
   # print("********",rem,"********")

    if rem==0:
        ans+=(ext-1)
    else:
        mul=10
        while(mul<=100000):
            st=rem*mul
            #print("___________",st)
            rr=mul//10
            st+=rr
            j=m-st%m
            if j==m:
                rr=mul//10
            else:
                rr=mul//10+j
            while(rr%mul==rr%(mul*10)):
               # print(rr)
                if cnt[rr]>0:
                    ans+=cnt[rr]
                rr+=m
            mul*=10
    cnt[arr[i]]+=1
print(ans)


n, k = map(int, input().split())

a = list(map(int, input().split()))

rem = dict()

pow10 = [10**j for j in range(11)]

ans = 0

for ai in a:
    key = len(str(ai))
    if key not in rem:
        rem[key] = dict()
    if ai % k not in rem[key]:
        rem[key][ai % k] = 0
    rem[key][ai % k] += 1

for ai in a:
    for j in range(1, 11):
        if j in rem:
            key = (-(ai * pow10[j])) % k
            if key in rem[j]:
                ans += rem[j][key]

for ai in a:
    if int(str(ai) + str(ai)) % k == 0:
        ans -= 1

print(ans)


from math import log10
from collections import Counter

n,k=[int(x) for x in input().split()]
lst=[int(x) for x in input().split()]
lst2=[]

for i in range(n):
    lst2.append(((lst[i]%k),len(str(lst[i]))))

dp = [[] for i in range(12)]
for j in lst2:
    dp[j[1]].append(j[0])
for i in range(12):
    if len(dp[i]) > 0:
        dp[i] = Counter(dp[i])
ans = 0
for i in lst:
    for j in range(2, 12):
        v1 = ((i%k) * pow(10, j-1))%k
        if (k - v1)%k in  dp[j-1]:
            ans=ans+dp[j-1][(k-v1)%k]
for i in lst:
    if int(str(i)+str(i))%k==0 :
        ans=ans-1
print(ans)


from collections import defaultdict
from string import ascii_lowercase
from sys import stdin, stdout
input = stdin.readline

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    mod = [defaultdict(int) for i in range(11)]  # number length 1-10, 1-indexed
    for val in a:
        mod[len(str(val))][val % k] += 1

    pairs = 0
    for val in a:
        for _len in range(1, 11):
            mod1 = (val * 10**_len) % k
            mod2 = k - mod1 if mod1 != 0 else 0
            pairs += mod[_len][mod2]
            if len(str(val)) == _len and val % k == mod2:
                pairs -= 1
    print(pairs)

if __name__ == '__main__':
    main()


from collections import defaultdict
from string import ascii_lowercase
from sys import stdin, stdout
input = stdin.readline

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    mod = [defaultdict(int) for i in range(11)]  # number length 1-10, 1-indexed
    for val in a:
        mod[len(str(val))][val % k] += 1

    pairs = 0
    for val in a:
        for _len in range(1, 10):
            mod1 = (val * 10**_len) % k
            mod2 = k - mod1 if mod1 != 0 else 0
            pairs += mod[_len][mod2]
            if len(str(val)) == _len and val % k == mod2:
                pairs -= 1
    print(pairs)

if __name__ == '__main__':
    main()


n = input()
(n,k) = n.split(" ")
arr = input()
arr = arr.split(" ")
store = {}

n = int(n)
k = int(k)

for x in arr:
	x = int(x)
	rem = x%k
	dig = 0
	while x>0:
		dig+=1
		x//=10

	if not dig in store:
		store[dig] = {}
		store[dig][rem]=1
	else:
		if not rem in store[dig]:
			store[dig][rem] = 1
		else:
			store[dig][rem]+=1

cnt=0
for x in arr:
	x = int(x)
	rem = x%k
	dig = 0
	while x>0:
		dig+=1
		x//=10

	for i in range(1,11):
		l = 10**i
		l = l%k
		l = (k-(rem*l)%k)%k

		if i in store:
			if l in store[i]:
				cnt += store[i][l]
				if l == rem and dig==i:
					cnt-=1

print(cnt)
//


n = input()
(n,k) = n.split(" ")
arr = input()
arr = arr.split(" ")
store = {}

n = int(n)
k = int(k)

for x in arr:
	x = int(x)
	rem = x%k
	dig = 0
	while x>0:
		dig+=1
		x//=10

	if not dig in store:
		store[dig] = {}
		store[dig][rem]=1
	else:
		if not rem in store[dig]:
			store[dig][rem] = 1
		else:
			store[dig][rem]+=1

cnt=0
for x in arr:
	x = int(x)
	rem = x%k
	dig = 0
	while x>0:
		dig+=1
		x//=10

	for i in range(1,11):
		l = 10**i
		l = l%k
		l = (k-(rem*l)%k)%k

		if i in store:
			if l in store[i]:
				cnt += store[i][l]
				if l == rem and dig==i:
					cnt-=1

print(cnt)


n = input()
(n,k) = n.split(" ")
arr = input()
arr = arr.split(" ")
store = {}

n = int(n)
k = int(k)

for x in arr:
	x = int(x)
	rem = x%k
	dig = 0
	while x>0:
		dig+=1
		x//=10

	if not dig in store:
		store[dig] = {}
		store[dig][rem]=1
	else:
		if not rem in store[dig]:
			store[dig][rem] = 1
		else:
			store[dig][rem]+=1

cnt=0
for x in arr:
	x = int(x)
	rem = x%k
	dig = 0
	while x>0:
		dig+=1
		x//=10

	for i in range(1,11):
		l = 10**i
		l = l%k
		l = (k-(rem*l)%k)%k

		if i in store:
			if l in store[i]:
				cnt += store[i][l]
				if l == rem and dig==i:
					cnt-=1

print(cnt)
#


n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=[]
for i in range(11):
    c={}
    for j in range(n):
        d=(a[j]*(10**i))%k
        if d in c.keys():
            c[d]+=1
        else:
            c[d]=1
    b.append(c)

s=0
for i in range(n):
    c=a[i]%k
    d=(k-c)%k
    if d in b[len(str(a[i]))]:
        s+=b[len(str(a[i]))][d]
    if (a[i]*(10**len(str(a[i]))))%k==d:
        s-=1
print(s)


def main():
    n, k = map(int, input().split())
    aa, cnt, res = [], {}, 0
    scale = [10 ** i + 1 for i in range(11)]
    for w in input().split():
        a, s = int(w), len(w)
        aa.append(a)
        if not a * scale[s] % k:
            res -= 1
        t = (s, a % k)
        cnt[t] = cnt.get(t, 0) + 1
    scale = [1 - i for i in scale]
    for a in aa:
        for s in range(1, 11):
            x = a * scale[s] % k
            res += cnt.get((s, x), 0)
    print(res)

if __name__ == '__main__':
    main()


def get_len(num):
    cnt = 0
    while num != 0:
        num //= 10
        cnt += 1
    return cnt

def work(n, a, k):
    d = {}
    for i in range(n):
        for j in range(11):
            num = a[i] * pow(10, j) % k
            if d.get((num, j)) is None:
                d[(num, j)] = 1
            else:
                d[(num, j)] += 1
    cnt = 0
    for i in range(n):
        length = get_len(a[i])
        num = (k - a[i] % k) % k
        if d.get((num, length)) is not None:
            cnt += d[(num, length)]
        if (a[i] * pow(10, length) + a[i]) % k == 0:
            cnt -= 1
    return cnt

n, k = map(int, input().split())
a = tuple(map(int, input().split()))
print(work(n, a, k))


import bisect

n,k=map(int,input().split())
A=list(map(int,input().split()))

B=[None]*10

for i in range(10):
    B[i]=sorted([A[l]*(10**i)%k for l in range(n)])

ANS=0
for i in range(n):
    L=len(str(A[i]))
    x=(k-A[i]%k)%k

    if A[i]*(10**L)%k==x:
        ANS-=1

    ANS+=bisect.bisect_right(B[L],x)-bisect.bisect_left(B[L],x)

print(ANS)


import bisect

n,k=map(int,input().split())
A=list(map(int,input().split()))

B=[None]*9

for i in range(9):
    B[i]=sorted([A[l]*(10**i)%k for l in range(n)])

ANS=0
for i in range(n):
    L=len(str(A[i]))
    x=(k-A[i]%k)%k

    if A[i]*(10**L)%k==x:
        ANS-=1

    ANS+=bisect.bisect_right(B[L],x)-bisect.bisect_left(B[L],x)

print(ANS)


n,k=map(int,input().split())
A=list(map(int,input().split()))

D=[dict() for i in range(10)]
for i in range(n):
    for j in range(1,11):
        D[j-1][A[i]*(10**j)%k]=D[j-1].get((A[i]*(10**j)%k),0)+1

ANS=0
for i in range(n):
    L=len(str(A[i]))
    x=-A[i]%k

    if A[i]*(10**L)%k==x:
        ANS-=1

    ANS+=D[L-1].get(x,0)

print(ANS)


n,k=map(int,input().split())
A=list(map(int,input().split()))

D=dict()
for i in range(n):
    for j in range(1,11):
        u=A[i]*pow(10,j)%k
        D[j,u]=D.get((j,u),0)+1

ANS=0
for i in range(n):
    L=len(str(A[i]))
    x=-A[i]%k

    if A[i]*pow(10,L)%k==x:
        ANS+=D.get((L,x),0)-1
    else:
        ANS+=D.get((L,x),0)

print(ANS)


n,k=map(int,input().split())
A=list(map(int,input().split()))

D=[dict() for i in range(10)]
for i in range(n):
    for j in range(1,11):
        D[j-1][A[i]*(10**j)%k]=D[j-1].get((A[i]*(10**j)%k),0)+1

ANS=0
for i in range(n):
    L=len(str(A[i]))
    x=(k-A[i]%k)%k

    if A[i]*(10**L)%k==x:
        ANS-=1

    ANS+=D[L-1].get(x,0)

print(ANS)


n,k=map(int,input().split())
A=list(map(int,input().split()))

D=dict()
for i in range(n):
    for j in range(1,11):
        D[j,A[i]*(10**(j))%k]=D.get((j,A[i]*(10**(j))%k),0)+1

ANS=0
for i in range(n):
    L=len(str(A[i]))
    x=(k-A[i]%k)%k

    if A[i]*(10**L)%k==x:
        ANS-=1

    ANS+=D.get((L,x),0)

print(ANS)


n,k=map(int,input().split())
A=list(map(int,input().split()))

D=dict()
for a in A:
    for j in range(1,11):
        u=a*pow(10,j)%k
        D[j,u]=D.get((j,u),0)+1

ANS=0
for a in A:
    L=len(str(a))
    x=-a%k

    if a*pow(10,L)%k==x:
        ANS+=D.get((L,x),0)-1
    else:
        ANS+=D.get((L,x),0)

print(ANS)


n,k=map(int,input().split())
A=list(map(int,input().split()))

D=dict()
for i in range(n):
    for j in range(10):
        D[j+1,A[i]*(10**(j+1))%k]=D.get((j+1,A[i]*(10**(j+1))%k),0)+1

ANS=0
for i in range(n):
    L=len(str(A[i]))
    x=(k-A[i]%k)%k

    if A[i]*(10**L)%k==x:
        ANS-=1

    ANS+=D.get((L,x),0)

print(ANS)


n,k=map(int,input().split())
A=list(map(int,input().split()))

B=[None]*9

for i in range(9):
    B[i]=[A[l]*(10**i)%k for l in range(n)]

ANS=0
for i in range(n):
    L=len(str(A[i]))
    x=(k-A[i]%k)%k

    ANS+=B[L].count(x)
    if B[L][i]==x:
        ANS-=1

print(ANS)


n,k=map(int,input().split())
A=list(map(int,input().split()))

B=[None]*10

for i in range(10):
    B[i]=[A[l]*(10**i)%k for l in range(n)]

ANS=0
for i in range(n):
    L=len(str(A[i]))
    x=(k-A[i]%k)%k

    ANS+=B[L].count(x)
    if B[L][i]==x:
        ANS-=1

print(ANS)


n,k=map(int,input().split())
A=list(map(int,input().split()))

D=dict()
for i in range(n):
    for j in range(11):
        D[j,A[i]*(10**j)%k]=D.get((j,A[i]*(10**j)%k),0)+1

ANS=0
for i in range(n):
    L=len(str(A[i]))
    x=(k-A[i]%k)%k

    if A[i]*(10**L)%k==x:
        ANS-=1

    ANS+=D.get((L,x),0)

print(ANS)


import bisect

n,k=map(int,input().split())
A=list(map(int,input().split()))

B=[None]*10
for i in range(10):
    B[i]=sorted([A[l]*(10**(i+1))%k for l in range(n)])

ANS=0
for i in range(n):
    if A[i]*(10**len(str(A[i])))%k==(k-A[i]%k)%k:
        ANS-=1

    ANS+=bisect.bisect_right(B[len(str(A[i]))-1],(k-A[i]%k)%k)-bisect.bisect_left(B[len(str(A[i]))-1],(k-A[i]%k)%k)

print(ANS)


n,k=map(int,input().split())
A=list(map(int,input().split()))

D=dict()
for i in range(n):
    for j in range(10):
        D[j,A[i]*(10**j)%k]=D.get((j,A[i]*(10**j)%k),0)+1

ANS=0
for i in range(n):
    L=len(str(A[i]))
    x=(k-A[i]%k)%k

    if A[i]*(10**L)%k==x:
        ANS-=1

    ANS+=D.get((L,x),0)

print(ANS)


n,k=map(int,input().split())
A=list(map(int,input().split()))

D=dict()
for i in range(n):
    for j in range(1,11):
        u=A[i]*(10**j)%k
        D[j,u]=D.get((j,u),0)+1

ANS=0
for i in range(n):
    L=len(str(A[i]))
    x=-A[i]%k

    if A[i]*(10**L)%k==x:
        ANS+=D.get((L,x),0)-1
    else:
        ANS+=D.get((L,x),0)

print(ANS)


import sys
input = sys.stdin.readline

n,k=map(int,input().split())
A=list(map(int,input().split()))

D=[dict() for i in range(10)]
for i in range(n):
    for j in range(1,6):
        D[j-1][A[i]*(10**j)%k]=D[j-1].get((A[i]*(10**j)%k),0)+1

ANS=0
for i in range(n):
    L=len(str(A[i]))
    x=-A[i]%k

    if A[i]*(10**L)%k==x:
        ANS-=1

    ANS+=D[L-1].get(x,0)

print(ANS)


import sys
input = sys.stdin.readline
from collections import Counter

n,k=map(int,input().split())
A=list(map(int,input().split()))

D=[Counter() for i in range(11)]
for a in A:
    for j in range(1,11):
        D[j][a*(10**j)%k]+=1

ANS=0
for a in A:
    L=len(str(a))
    x=-a%k

    if a*(10**L)%k==x:
        ANS-=1

    ANS+=D[L][x]

print(ANS)


n, k = map(int, input().split())
a = [int(x) for x in input().split()]
rda = []
for j in range(12):
    rd = dict()
    x = pow(10, j)
    for i in range(n):
        r = (a[i]*x)%k
        rd[r] = rd.setdefault(r, 0) + 1
    rda.append(rd)
ans = 0
for i in range(n):
    r = a[i]%k
    ln = len(str(a[i]))
    x = pow(10, ln)
    if r == 0: r = k
    if k-r in rda[ln]:
        ans += rda[ln][k-r]
        if (a[i]*x)%k == k-r:
            ans -= 1
print(ans)


rd = lambda: list(map(int, input().split()))

(n, k), a = rd(), rd()

def proceed(a):
    global n, k

    b = [{} for _ in range(10)]

    ans = 0
    for i in range(n - 1, 0, -1):
        if k > 10 ** 8:
            continue

        cur = a[i] % k
        ln = len(str(a[i]))

        if cur not in b[ln]:
            b[ln][cur] = 0
        b[ln][cur] += 1

        for j in range(10):
            cur = (k - a[i - 1] * 10 ** j % k) % k
            ans += b[j][cur] if cur in b[j] else 0
    return ans

print(proceed(a) + proceed(a[::-1]))


#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 1e6 + 5;

int N, M, s, t;
vector<int> adj[maxn];
int out[maxn];
int dist[maxn];

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N >> M;
  while(M--){
    int u, v; cin >> u >> v;
    adj[v].eb(u);
    out[u]++;
  }
  cin >> s >> t;
  deque<int> dq;
  memset(dist, -1, sizeof dist);
  dist[t] = 0;
  dq.pb(t);
  while(dq.size()){
    int u = dq.front(); dq.pop_front();
    for(int v : adj[u]){
      out[v]--;
      if(out[v] == 0){
        if(dist[v] == -1 || dist[v] > dist[u]){
          dist[v] = dist[u];
          dq.push_front(v);
        }
      }
      else{
        if(dist[v] == -1 || dist[v] > dist[u] + 1){
          dist[v] = dist[u] + 1;
          dq.push_back(v);
        }
      }
    }
  }
  cout << dist[s];
}


#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm,tune=native")
#include <bits/stdc++.h>
#define DEBUG 1
using namespace std;

namespace output{
    void __(short x){cout<<x;}
    void __(unsigned x){cout<<x;}
    void __(int x){cout<<x;}
    void __(long long x){cout<<x;}
    void __(unsigned long long x){cout<<x;}
    void __(double x){cout<<x;}
    void __(long double x){cout<<x;}
    void __(char x){cout<<x;}
    void __(const char*x){cout<<x;}
    void __(const string&x){cout<<x;}
    void __(bool x){cout<<(x?"true":"false");}
    template<class S,class T>
    void __(const pair<S,T>&x){__(DEBUG?"(":""),__(x.first),__(DEBUG?", ":" "),__(x.second),__(DEBUG?")":"");}
    template<class T>
    void __(const vector<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const set<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const multiset<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class S,class T>
    void __(const map<S,T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    void pr(){cout<<"\n";}
    template<class S,class... T>
    void pr(const S&a,const T&...b){__(a);if(sizeof...(b))__(' ');pr(b...);}
}

using namespace output;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,char> pic;
typedef pair<double,double> pdd;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;

#define pb push_back
#define fox(i,x,y) for(int i=(x);i<=(y);i++)
#define foxr(i,x,y) for(int i=(y);i>=(x);i--)
#define F first
#define S second

const int MN = 1e6+6;
int n, m, i, x, y, s, t, deg[MN], tmp[MN], dp[MN], vs[MN];
struct pq{bool operator()(const pii&i,const pii&j){return i.S>j.S;}};
priority_queue<pii,vector<pii>,pq> q;
vi rev[MN];

int main(){
    for(scanf("%d%d",&n,&m),i=1;i<=m;i++){
        scanf("%d%d",&x,&y);
        rev[y].pb(x);
        deg[x] ++;
    }
    scanf("%d%d",&s,&t);
    memset(dp,0x3f,sizeof(dp));
    q.push({t,0});
    while(q.size()){
        pii cur=q.top(); q.pop();
        if(vs[cur.F]) continue;
        vs[cur.F] = 1;
        dp[cur.F] = cur.S;
        for(auto v : rev[cur.F]){
            if(!vs[v]){
                deg[v]--;
                tmp[v]=max(tmp[v],cur.S);
                if(!deg[v]) q.push({v,tmp[v]});
                else q.push({v,cur.S+1});
            }
        }
    }
    if(!vs[s]) printf("-1\n");
    else printf("%d\n",dp[s]);
    return 0;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ll long long int
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int main()
{
    fast();
    int sz=1e6+6;
    int n,m; cin>>n>>m;
    int val[n+1],inv[n+1]={0},vis[n+1]={0};
    for(int i=1;i<=n;i++) val[i]=sz;
    vector<int> adj[n+1];
    for(int i=0;i<m;i++)
    {
        int u,v; cin>>u>>v;
        adj[v].pb(u);
        inv[u]++;
    }
    int st,dest; cin>>st>>dest;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    pq.push({0,dest});
    val[dest]=0;
    while(pq.size())
    {
        pair<int,int> tmp=pq.top(); pq.pop();
        int u=tmp.s;
        // cout<<u<<" "<<val[u]<<endl;
        // if(u==st) break;
        if(vis[u]) continue;
        vis[u]=1;
        for(int i=0;i<adj[u].size();i++)
        {
            int v=adj[u][i];
            // cout<<"     "<<v<<endl;
            inv[v]--;
            if(inv[v]==0)
            {
                if(val[u]<val[v])
                {
                    val[v]=val[u];
                    pq.push({0,v});
                }
            }
            else
            {
                if(val[v]==sz)
                {
                    val[v]=val[u]+1;
                    pq.push({inv[v],v});
                }
            }
        }
    }
    if(val[st]==sz) cout<<-1;
    else cout<<val[st];
    return 0;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ll long long int
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const int sz=1e6+6;
int n,m,start,dest,t=1;
vector<int> adj[sz];
int st[sz],en[sz],vis[sz],val[sz],acc[sz];
void update(int u,int v,int& mx)
{
    acc[u]|=acc[v];
    if(acc[v]) mx=min(mx,val[v]);
    else val[u]=1;
}
void dfs(int u)
{
    // cout<<"start : "<<u<<endl;
    st[u]=t++;
    en[u]=0;
    int mx=sz;
    for(int i=0;i<adj[u].size();i++)
    {
        int v=adj[u][i];
        // cout<<v<<endl;
        if(vis[v])
        {
            update(u,v,mx);
            // cout<<mx<<endl;
            continue;
        }
        if(st[v]==0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else if(en[v]>0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else val[u]=1;
        // cout<<mx<<endl;
    }
    for(int i=0;i<adj[u].size();i++)
    {
        int w=adj[start][i];
        if(mx==sz || val[w]!=mx) val[u]=1;
    }
    val[u]+=mx;
    vis[u]=1;
    en[u]=t++;
    // cout<<"end : "<<u<<" "<<val[u]<<endl<<endl;
}
int main()
{
    fast();
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v; cin>>u>>v;
        adj[u].pb(v);
    }
    cin>>start>>dest;
    vis[dest]=1;
    acc[dest]=1;
    val[dest]=0;
    dfs(start);
    // for(int i=1;i<=n;i++) cout<<i%10<<" "; cout<<endl;
    // for(int i=1;i<=n;i++) cout<<acc[i]<<" "; cout<<endl;
    // for(int i=1;i<=n;i++) cout<<val[i]<<" "; cout<<endl;
    // int mx=0;
    // for(int i=0;i<adj[start].size();i++)
    // {
    //     int v=adj[start][i];
    //     if(val[v]!=val[start]) mx=1;
    // }
    // cout<<mx<<endl;
    if(acc[start]) cout<<val[start];
    else cout<<-1;
    return 0;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ll long long int
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const int sz=1e6+6;
int n,m,start,dest,t=1;
vector<int> adj[sz];
int st[sz],en[sz],vis[sz],val[sz],acc[sz];
void update(int u,int v,int& mx)
{
    acc[u]|=acc[v];
    if(acc[v]) mx=max(mx,val[v]);
    else val[u]=1;
}
void dfs(int u)
{
    st[u]=t++;
    en[u]=0;
    int mx=0;
    for(int i=0;i<adj[u].size();i++)
    {
        int v=adj[u][i];
        if(vis[v])
        {
            update(u,v,mx);
            continue;
        }
        if(st[v]==0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else if(en[v]>0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else val[u]=1;
    }
    val[u]+=mx;
    vis[u]=1;
    en[u]=t++;
}
int main()
{
    fast();
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v; cin>>u>>v;
        adj[u].pb(v);
    }
    cin>>start>>dest;
    vis[dest]=1;
    acc[dest]=1;
    dfs(start);
    if(acc[start]) cout<<val[start];
    else cout<<-1;
    return 0;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ll long long int
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const int sz=1e6+6;
int n,m,start,dest,t=1;
vector<int> adj[sz];
int st[sz],en[sz],vis[sz],val[sz],acc[sz];
void update(int u,int v,int& mx)
{
    acc[u]|=acc[v];
    if(acc[v]) mx=min(mx,val[v]);
    else val[u]=1;
}
void dfs(int u)
{
    // cout<<"start : "<<u<<endl;
    st[u]=t++;
    en[u]=0;
    int mx=sz;
    for(int i=0;i<adj[u].size();i++)
    {
        int v=adj[u][i];
        if(vis[v])
        {
            update(u,v,mx);
            continue;
        }
        if(st[v]==0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else if(en[v]>0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else val[u]=1;
    }
    val[u]+=mx;
    vis[u]=1;
    en[u]=t++;
    // cout<<"end : "<<u<<" "<<val[u]<<endl<<endl;
}
int main()
{
    fast();
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v; cin>>u>>v;
        adj[u].pb(v);
    }
    cin>>start>>dest;
    vis[dest]=1;
    acc[dest]=1;
    dfs(start);
    // for(int i=1;i<=n;i++) cout<<i%10<<" "; cout<<endl;
    // for(int i=1;i<=n;i++) cout<<acc[i]<<" "; cout<<endl;
    // for(int i=1;i<=n;i++) cout<<val[i]<<" "; cout<<endl;
    int mx=0;
    for(int i=0;i<adj[start].size();i++)
    {
        int v=adj[start][i];
        if(val[v]!=val[start]) mx=1;
    }
    if(acc[start]) cout<<val[start]+mx;
    else cout<<-1;
    return 0;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ll long long int
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const int sz=1e6+6;
int n,m,start,dest,t=1;
vector<int> adj[sz];
int st[sz],en[sz],vis[sz],val[sz],acc[sz];
void update(int u,int v,int& mx)
{
    acc[u]|=acc[v];
    if(acc[v]) mx=min(mx,val[v]);
    else val[u]=1;
}
void dfs(int u)
{
    // cout<<"start : "<<u<<endl;
    st[u]=t++;
    en[u]=0;
    int mx=sz;
    for(int i=0;i<adj[u].size();i++)
    {
        int v=adj[u][i];
        // cout<<v<<endl;
        if(vis[v])
        {
            update(u,v,mx);
            // cout<<mx<<endl;
            continue;
        }
        if(st[v]==0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else if(en[v]>0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else val[u]=1;
        // cout<<mx<<endl;
    }
    for(int i=0;i<adj[u].size();i++)
    {
        int w=adj[u][i];
        if(mx==sz || val[w]!=mx) val[u]=1;
    }
    val[u]+=mx;
    vis[u]=1;
    en[u]=t++;
    // cout<<"end : "<<u<<" "<<val[u]<<endl<<endl;
}
int main()
{
    fast();
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v; cin>>u>>v;
        adj[u].pb(v);
    }
    cin>>start>>dest;
    vis[dest]=1;
    acc[dest]=1;
    val[dest]=0;
    dfs(start);
    // for(int i=1;i<=n;i++) cout<<i%10<<" "; cout<<endl;
    // for(int i=1;i<=n;i++) cout<<acc[i]<<" "; cout<<endl;
    // for(int i=1;i<=n;i++) cout<<val[i]<<" "; cout<<endl;
    // int mx=0;
    // for(int i=0;i<adj[start].size();i++)
    // {
    //     int v=adj[start][i];
    //     if(val[v]!=val[start]) mx=1;
    // }
    // cout<<mx<<endl;
    if(acc[start]) cout<<val[start];
    else cout<<-1;
    return 0;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ll long long int
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const int sz=1e6+6;
int n,m,start,dest,t=1;
vector<int> adj[sz];
int st[sz],en[sz],vis[sz],val[sz],acc[sz];
void update(int u,int v,int& mx)
{
    acc[u]|=acc[v];
    if(acc[v]) mx=min(mx,val[v]);
    else val[u]=1;
}
void dfs(int u)
{
    // cout<<"start : "<<u<<endl;
    st[u]=t++;
    en[u]=0;
    int mx=sz;
    for(int i=0;i<adj[u].size();i++)
    {
        int v=adj[u][i];
        if(vis[v])
        {
            update(u,v,mx);
            continue;
        }
        if(st[v]==0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else if(en[v]>0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else val[u]=1;
    }
    val[u]+=mx;
    vis[u]=1;
    en[u]=t++;
    // cout<<"end : "<<u<<" "<<val[u]<<endl<<endl;
}
int main()
{
    fast();
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v; cin>>u>>v;
        adj[u].pb(v);
    }
    cin>>start>>dest;
    vis[dest]=1;
    acc[dest]=1;
    dfs(start);
    // for(int i=1;i<=n;i++) cout<<i%10<<" "; cout<<endl;
    // for(int i=1;i<=n;i++) cout<<acc[i]<<" "; cout<<endl;
    // for(int i=1;i<=n;i++) cout<<val[i]<<" "; cout<<endl;
    // int mx=0,chk=0;
    // for(int i=0;i<adj[start].size();i++)
    // {
    //     int v=adj[start][i];
    //     if(acc[v]) mx=max(mx,val[v]);
    //     else chk=1;
    // }
    if(acc[start]) cout<<val[start];
    else cout<<-1;
    return 0;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ll long long int
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const int sz=1e6+6;
int n,m,start,dest,t=1;
vector<int> adj[sz];
int st[sz],en[sz],vis[sz],val[sz],acc[sz];
void update(int u,int v,int& mx)
{
    acc[u]|=acc[v];
    if(acc[v]) mx=min(mx,val[v]);
    else val[u]=1;
}
void dfs(int u)
{
    // cout<<"start : "<<u<<endl;
    st[u]=t++;
    en[u]=0;
    int mx=sz;
    for(int i=0;i<adj[u].size();i++)
    {
        int v=adj[u][i];
        // cout<<v<<endl;
        if(vis[v])
        {
            update(u,v,mx);
            // cout<<mx<<endl;
            continue;
        }
        if(st[v]==0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else if(en[v]>0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else val[u]=1;
        // cout<<mx<<endl;
    }
    for(int i=0;i<adj[u].size();i++)
    {
        int w=adj[u][i];
        if(val[w]!=mx) val[u]=1;
    }
    val[u]+=mx;
    vis[u]=1;
    en[u]=t++;
    // cout<<"end : "<<u<<" "<<val[u]<<endl<<endl;
}
int main()
{
    fast();
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v; cin>>u>>v;
        adj[u].pb(v);
    }
    cin>>start>>dest;
    vis[dest]=1;
    acc[dest]=1;
    val[dest]=0;
    dfs(start);
    // for(int i=1;i<=n;i++) cout<<i%10<<" "; cout<<endl;
    // for(int i=1;i<=n;i++) cout<<acc[i]<<" "; cout<<endl;
    // for(int i=1;i<=n;i++) cout<<val[i]<<" "; cout<<endl;
    // int mx=0;
    // for(int i=0;i<adj[start].size();i++)
    // {
    //     int v=adj[start][i];
    //     if(val[v]!=val[start]) mx=1;
    // }
    // cout<<mx<<endl;
    if(acc[start]) cout<<val[start];
    else cout<<-1;
    return 0;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ll long long int
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int main()
{
    fast();
    int sz=1e6+6;
    int n,m; cin>>n>>m;
    int val[n+1],inv[n+1]={0},vis[n+1]={0};
    for(int i=1;i<=n;i++) val[i]=sz;
    vector<int> adj[n+1];
    for(int i=0;i<m;i++)
    {
        int u,v; cin>>u>>v;
        adj[v].pb(u);
        inv[u]++;
    }
    int st,dest; cin>>st>>dest;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    pq.push({0,dest});
    val[dest]=0;
    while(pq.size())
    {
        pair<int,int> tmp=pq.top(); pq.pop();
        int u=tmp.s;
        // cout<<u<<" "<<val[u]<<endl;
        // if(u==st) break;
        if(vis[u]) continue;
        vis[u]=1;
        for(int i=0;i<adj[u].size();i++)
        {
            int v=adj[u][i];
            // cout<<"     "<<v<<endl;
            inv[v]--;
            if(inv[v]==0)
            {
                if(val[u]<val[v])
                {
                    val[v]=val[u];
                    pq.push({0,v});
                }
            }
            else
            {
                if(val[u]<val[v])
                {
                    val[v]=val[u]+1;
                    pq.push({inv[v],v});
                }
            }
        }
    }
    if(val[st]==sz) cout<<-1;
    else cout<<val[st];
    return 0;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ll long long int
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int main()
{
    fast();
    int n,m; cin>>n>>m;
    int sz=1e6+6;
    int q[4*sz],l,r;
    bool vis[n+1]={0};
    int val[n+1],inv[n+1]={0};
    vector<int> adj[n+1];
    for(int i=1;i<=n;i++) val[i]=sz;
    for(int i=0,u,v; i<m;i++)
    {
        cin>>u>>v;
        adj[v].pb(u);
        inv[u]++;
    }
    int st,dest; cin>>st>>dest;
    val[dest]=0;
    q[sz]=dest;
    l=sz; r=sz+1;
    while(l<r)
    {
        int u=q[l++];
        // cout<<u<<" "<<val[u]<<endl;
        if(u==st) break;
        if(vis[u]) continue;
        vis[u]=1;
        for(int i=0;i<adj[u].size();i++)
        {
            int v=adj[u][i];
            // cout<<"     "<<v<<endl;
            inv[v]--;
            if(inv[v]==0)
            {
                if(val[u]<val[v])
                {
                    val[v]=val[u];
                    q[--l]=v;
                }
            }
            else
            {
                if(val[u]<val[v])
                {
                    val[v]=val[u]+1;
                    q[r++]=v;
                }
            }
        }
    }
    if(val[st]==sz) cout<<-1;
    else cout<<val[st];
    return 0;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ll long long int
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const int sz=1e6+6;
int n,m,start,dest,t=1;
vector<int> adj[sz];
int st[sz],en[sz],vis[sz],val[sz],acc[sz];
void update(int u,int v,int& mx)
{
    acc[u]|=acc[v];
    if(acc[v]) mx=min(mx,val[v]);
    else val[u]=1;
}
void dfs(int u)
{
    // cout<<"start : "<<u<<endl;
    st[u]=t++;
    en[u]=0;
    int mx=sz;
    for(int i=0;i<adj[u].size();i++)
    {
        int v=adj[u][i];
        // cout<<v<<endl;
        if(vis[v])
        {
            update(u,v,mx);
            // cout<<mx<<endl;
            continue;
        }
        if(st[v]==0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else if(en[v]>0)
        {
            dfs(v);
            update(u,v,mx);
        }
        else val[u]=1;
        // cout<<mx<<endl;
    }
    for(int i=0;i<adj[u].size();i++)
    {
        int w=adj[start][i];
        if(val[w]!=mx) val[u]=1;
    }
    val[u]+=mx;
    vis[u]=1;
    en[u]=t++;
    // cout<<"end : "<<u<<" "<<val[u]<<endl<<endl;
}
int main()
{
    fast();
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v; cin>>u>>v;
        adj[u].pb(v);
    }
    cin>>start>>dest;
    vis[dest]=1;
    acc[dest]=1;
    val[dest]=0;
    dfs(start);
    // for(int i=1;i<=n;i++) cout<<i%10<<" "; cout<<endl;
    // for(int i=1;i<=n;i++) cout<<acc[i]<<" "; cout<<endl;
    // for(int i=1;i<=n;i++) cout<<val[i]<<" "; cout<<endl;
    // int mx=0;
    // for(int i=0;i<adj[start].size();i++)
    // {
    //     int v=adj[start][i];
    //     if(val[v]!=val[start]) mx=1;
    // }
    // cout<<mx<<endl;
    if(acc[start]) cout<<val[start];
    else cout<<-1;
    return 0;
}


// hahaha finally :))
#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int , int> pii;

const int N = 1000*1000 + 10;

int st , en;
int nei[N] , d[N];

vector <int> adj[2][N];
set <pair <int , int> > s1 , s2;

void Dijkstra(){

	while(s1.size() || s2.size()){
		int u;

		if(s1.size() && !(*s1.begin()).F){

		   u = (*s1.begin()).S;

		   s1.erase(s1.begin());
		   s2.erase(mp(d[u] , u));

		   int maxx = 0;
		   for(int v : adj[0][u]){
			  d[u] = min(d[u] , d[v] + 1);
			  maxx = max(maxx , d[v]);
		   }

		   if(adj[0][u].size())
			   d[u] = min(d[u] , maxx);

		}
		else{

			u = (*s2.begin()).S;
			s2.erase(*s2.begin());
			s1.erase(mp(nei[u] , u));

		}

		for(int v : adj[1][u]){

		   if(s1.find(mp(nei[v] , v)) != s1.end()){

				s1.erase(mp(nei[v] , v));
				nei[v]--;
				s1.insert(mp(nei[v] , v));

		   }

		   if(s2.find(mp(d[v] , v)) != s2.end()){

				s2.erase(mp(d[v] , v));
				d[v] = min(d[v] , d[u] + 1);
				s2.insert(mp(d[v] , v));

		   }

	    }
	}

	return;
}

int main(){

    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

	int n , m , u , v;
	cin >> n >> m;

	for(int i = 0 ; i < m ; i++){
	   cin >> u >> v;

	   adj[0][--u].pb(--v);
	   adj[1][v].pb(u);
	}

	cin >> st >> en;
	st-- , en--;

	for(int i = 0 ; i < n ; i++){

	   nei[i] = adj[0][i].size();
	   s1.insert(mp(nei[i] , i));

	   if(i != en){
		   d[i] = N;
		   s2.insert(mp(d[i] , i));
		}
		else
		   s2.insert(mp(0 , i));
	}

	Dijkstra();

	cout << ((d[st] >= N) ? -1 : d[st]) << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 999999999
vector<int>e[100001];
vector<int>ed[100001];
int dis[100001];
int vis[100001];
void spfa(int s)
{
	memset(dis,0x3f,sizeof(dis));
	queue<int>q;
	dis[s]=0,vis[s]=1;
	q.push(s);
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		vis[u]=0;
		for(int i=0;i<e[u].size();i++)
		{
			int to=e[u][i];
			if(dis[to]>dis[u]+1)
			{
				dis[to]=dis[u]+1;
				if(!vis[to])
				{
					q.push(to);
					vis[to]=1;
				}
			}
		}
		int mx=0;
		for(int i=0;i<ed[u].size();i++)
			mx=max(mx,dis[ed[u][i]]);
		if(dis[u]>mx)
		{
			dis[u]=mx;
			vis[u]=1;
			q.push(u);
		}
	}
}
int main()
{
	int n,m;
  	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		ed[u].push_back(v);
		e[v].push_back(u);
	}
	int s,t;
	scanf("%d%d",&s,&t);
	spfa(t);
	printf("%d",(dis[s]>inf)?-1:dis[s]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 999999999
vector<int>e[1000001];
vector<int>ed[1000001];
int dis[1000001];
int vis[1000001];
void spfa(int s)
{
	memset(dis,0x3f,sizeof(dis));
	queue<int>q;
	dis[s]=0,vis[s]=1;
	q.push(s);
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		vis[u]=0;
		for(int i=0;i<e[u].size();i++)
		{
			int to=e[u][i];
			if(dis[to]>dis[u]+1)
			{
				dis[to]=dis[u]+1;
				if(!vis[to])
				{
					q.push(to);
					vis[to]=1;
				}
			}
		}
		int mx=0;
		for(int i=0;i<ed[u].size();i++)
			mx=max(mx,dis[ed[u][i]]);
		if(dis[u]>mx)
		{
			dis[u]=mx;
			vis[u]=1;
			q.push(u);
		}
	}
}
int main()
{
	int n,m;
  	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		ed[u].push_back(v);
		e[v].push_back(u);
	}
	int s,t;
	scanf("%d%d",&s,&t);
	spfa(t);
	printf("%d",(dis[s]>inf)?-1:dis[s]);
	return 0;
}


//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pob pop_back
#define forr(x) for(int i = 0; i < x; i++)
#define forrr(x) for(int j = 0; j < x; j++)
#define F first
#define S second
#define endl '\n'
#define pi pair<ll, ll>
#define mp make_pair
const ll N = 3e5 + 5, inf = 1e9 + 5;

int n;
int m;
int x, y;
vector<int> adj[N];
vector<int> adj2[N];
int dp[N];
set<pi> st;
int s;
int t;

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	forr(m)
	{
		cin >> x >> y;
		x --;
		y --;
		adj[x].pb(y);
		adj2[y].pb(x);
	}
	cin >> s >> t;
	s --;
	t --;
	forr(n)
	{
		dp[i] = inf;
	}
	st.insert({0, t});
	while(st.size())
	{
		auto u = *st.begin();
		st.erase(u);
		dp[u.S] = u.F;
		for(auto v : adj2[u.S])
		{
			int mi = inf, ma = -1;
			for(auto v2 : adj[v])
			{
				mi = min(mi, dp[v2]);
				ma = max(ma, dp[v2]);
			}
			if(min(mi + 1, ma) < dp[v])
			{
				st.insert({min(mi + 1, ma), v});
			}
		}
	}
	cout << (dp[s] >= inf ? -1 : dp[s]);
	return 0;
}


//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pob pop_back
#define forr(x) for(int i = 0; i < x; i++)
#define forrr(x) for(int j = 0; j < x; j++)
#define F first
#define S second
#define endl '\n'
#define pi pair<ll, ll>
#define mp make_pair
const ll N = 3e5 + 5, inf = 1e9 + 5;

int n;
int m;
int x, y;
vector<int> adj[N];
vector<int> adj2[N];
int dp[N];
set<pi> st;
int s;
int t;

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	forr(m)
	{
		cin >> x >> y;
		x --;
		y --;
		adj[x].pb(y);
		adj2[y].pb(x);
	}
	cin >> s >> t;
	s --;
	t --;
	forr(n)
	{
		dp[i] = inf;
	}
	st.insert({0, t});
	dp[t] = 0;
	while(st.size())
	{
		auto u = *st.begin();
		st.erase(u);
		for(auto v : adj2[u.S])
		{
			int mi = inf, ma = -1;
			for(auto v2 : adj[v])
			{
				mi = min(mi, dp[v2]);
				ma = max(ma, dp[v2]);
			}
			if(min(mi + 1, ma) < dp[v])
			{
				st.erase({dp[v], v});
				dp[v] = min(mi + 1, ma);
				st.insert({dp[v], v});
			}
		}
	}
	cout << (dp[s] >= inf ? -1 : dp[s]);
	return 0;
}


//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pob pop_back
#define forr(x) for(int i = 0; i < x; i++)
#define forrr(x) for(int j = 0; j < x; j++)
#define F first
#define S second
#define endl '\n'
#define pi pair<ll, ll>
#define mp make_pair
const ll N = 1e6 + 5, inf = 1e9 + 5;

int n;
int m;
int x, y;
vector<int> adj[N];
vector<int> adj2[N];
int dp[N];
set<pi> st;
int s;
int t;
int mark[N];

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	forr(m)
	{
		cin >> x >> y;
		x --;
		y --;
		adj[x].pb(y);
		adj2[y].pb(x);
	}
	cin >> s >> t;
	s --;
	t --;
	forr(n)
	{
		dp[i] = inf;
	}
	st.insert({0, t});
	dp[t] = 0;
	while(st.size())
	{
		auto u = *st.begin();
		st.erase(u);
		if(mark[u.S])
			continue;
		mark[u.S] = 1;
		for(auto v : adj2[u.S])
		{
			int mi = inf, ma = -1;
			for(auto v2 : adj[v])
			{
				mi = min(mi, dp[v2]);
				ma = max(ma, dp[v2]);
			}
			if(min(mi + 1, ma) < dp[v])
			{
				st.erase({dp[v], v});
				dp[v] = min(mi + 1, ma);
				st.insert({dp[v], v});
			}
		}
	}
	cout << (dp[s] >= inf ? -1 : dp[s]);
	return 0;
}


//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pob pop_back
#define forr(x) for(int i = 0; i < x; i++)
#define forrr(x) for(int j = 0; j < x; j++)
#define F first
#define S second
#define endl '\n'
#define pi pair<ll, ll>
#define mp make_pair
const ll N = 1e6 + 5, inf = 1e9 + 5;

int n;
int m;
int x, y;
vector<int> adj[N];
vector<int> adj2[N];
int dp[N];
set<pi> st;
int s;
int t;

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	forr(m)
	{
		cin >> x >> y;
		x --;
		y --;
		adj[x].pb(y);
		adj2[y].pb(x);
	}
	cin >> s >> t;
	s --;
	t --;
	forr(n)
	{
		dp[i] = inf;
	}
	st.insert({0, t});
	dp[t] = 0;
	while(st.size())
	{
		auto u = *st.begin();
		st.erase(u);
		for(auto v : adj2[u.S])
		{
			int mi = inf, ma = -1;
			for(auto v2 : adj[v])
			{
				mi = min(mi, dp[v2]);
				ma = max(ma, dp[v2]);
			}
			if(min(mi + 1, ma) < dp[v])
			{
				st.erase({dp[v], v});
				dp[v] = min(mi + 1, ma);
				st.insert({dp[v], v});
			}
		}
	}
	cout << (dp[s] >= inf ? -1 : dp[s]);
	return 0;
}


//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pob pop_back
#define forr(x) for(int i = 0; i < x; i++)
#define forrr(x) for(int j = 0; j < x; j++)
#define F first
#define S second
#define endl '\n'
#define pi pair<ll, ll>
#define mp make_pair
const ll N = 3e5 + 5, inf = 1e9 + 5;

int n;
int m;
int x, y;
vector<int> adj[N];
vector<int> adj2[N];
int dp[N];
set<pi> st;
int s;
int t;

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	forr(m)
	{
		cin >> x >> y;
		x --;
		y --;
		adj[x].pb(y);
		adj2[y].pb(x);
	}
	cin >> s >> t;
	s --;
	t --;
	forr(n)
	{
		dp[i] = inf;
	}
	st.insert({0, t});
	dp[t] = 0;
	while(st.size())
	{
		auto u = *st.begin();
		st.erase(u);
		int mi = inf, ma = -1;
		for(auto v : adj[u.S])
		{
			mi = min(mi, dp[v]);
			ma = max(ma, dp[v]);
		}
		if(mi == ma&& u.S != t)
		{
			dp[u.S] = mi;
		}
		else if(u.S != t)
		{
			dp[u.S] = mi + 1;
		}
		for(auto v : adj2[u.S])
		{
			if(dp[v] > dp[u.S])
			{
				st.erase({dp[v], v});
				dp[v] = dp[u.S];
				st.insert({dp[v], v});
			}
		}
	}
	cout << dp[s];
	return 0;
}


//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pob pop_back
#define forr(x) for(int i = 0; i < x; i++)
#define forrr(x) for(int j = 0; j < x; j++)
#define F first
#define S second
#define endl '\n'
#define pi pair<ll, ll>
#define mp make_pair
const ll N = 3e5 + 5, inf = 1e9 + 5;

int n;
int m;
int x, y;
vector<int> adj[N];
vector<int> adj2[N];
int dp[N];
set<pi> st;
int s;
int t;

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	forr(m)
	{
		cin >> x >> y;
		x --;
		y --;
		adj[x].pb(y);
		adj2[y].pb(x);
	}
	cin >> s >> t;
	s --;
	t --;
	forr(n)
	{
		dp[i] = inf;
	}
	st.insert({0, t});
	dp[t] = 0;
	while(st.size())
	{
		auto u = *st.begin();
		st.erase(u);
		int mi = inf, ma = -1;
		for(auto v : adj[u.S])
		{
			mi = min(mi, dp[v]);
			ma = max(ma, dp[v]);
		}
		if(mi == ma&& u.S != t)
		{
			dp[u.S] = mi;
		}
		else if(u.S != t)
		{
			dp[u.S] = mi + 1;
		}
		for(auto v : adj2[u.S])
		{
			if(dp[v] > dp[u.S])
			{
				st.erase({dp[v], v});
				dp[v] = dp[u.S];
				st.insert({dp[v], v});
			}
		}
	}
	cout << (dp[s] >= inf ? -1 : dp[s]);
	return 0;
}


//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pob pop_back
#define forr(x) for(int i = 0; i < x; i++)
#define forrr(x) for(int j = 0; j < x; j++)
#define F first
#define S second
#define endl '\n'
#define pi pair<ll, ll>
#define mp make_pair
const ll N = 1e6 + 5, inf = 1e9 + 5;

int n;
int m;
int x, y;
vector<int> adj[N];
vector<int> adj2[N];
int dp[N];
set<pi> st;
int s;
int t;
int mark[N];
int cnt[N];

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	forr(m)
	{
		cin >> x >> y;
		x --;
		y --;
		adj[x].pb(y);
		adj2[y].pb(x);
	}
	cin >> s >> t;
	s --;
	t --;
	forr(n)
	{
		dp[i] = inf;
	}
	st.insert({0, t});
	dp[t] = 0;
	while(st.size())
	{
		auto u = *st.begin();
		st.erase(u);
		if(mark[u.S])
			continue;
		mark[u.S] = 1;
		for(auto v : adj2[u.S])
		{
			cnt[v] ++;
			int mi = u.F;
			int ma = inf;
			if(cnt[v] == adj[v].size())
				ma = mi;
			if(min(mi + 1, ma) < dp[v])
			{
				st.erase({dp[v], v});
				dp[v] = min(mi + 1, ma);
				st.insert({dp[v], v});
			}
		}
	}
	cout << (dp[s] >= inf ? -1 : dp[s]);
	return 0;
}


//Be Name Khoda
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma optimize O3
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); }
#define MKP make_pair
#define RETD(x) { cout << fixed << setprecision(15) << x; exit(0); }
#define GEI(x) scanf("%d",&x)
#define GEL(x) scanf("%lld",&x)
#define ALL(x) x.begin(),x.end()
const ll M=4e5+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;

vll h[M];
ll cnt[M];
ll dis[M];
ll ss[M];
ll n,m;
ll s,t;
vll v;
ll qu[M],qh,qt;
int main()
{
	GEL(n);GEL(m);
    For(i,0,m)
    {
        ll u,v;
        GEL(u);GEL(v);
        u--;v--;
        h[v].PB(u);
        cnt[u]++;
    }
    GEL(s);GEL(t);
    s--;t--;
    memset(dis,63,sizeof dis);
    v.PB(t);
    For(i,0,n)
    {
        qh=qt=0;
        for (ll x:v)
        {
            qu[qh++]=x;
        }
        while (qh!=qt)
        {
            ll f=qu[qt++];
            ss[f]++;
            dis[f]=i;
            for (ll y:h[f])
            {
                cnt[y]--;
                if (!cnt[y])
                    qu[qh++]=y;
            }
        }
        v.clear();
        For(j,0,qh)
        {
            for (ll y:h[qu[j]])
            {
                if (dis[y]>i)
                {
                    cnt[y]=0;
                    dis[y]=i;
                    v.PB(y);
                }
            }
        }
    }
    /*For(i,0,n)
    {
        ER(i);
        ER(cnt[i]);
        ER(ss[i]);
        ER(dis[i]);
    }//*/
    if (dis[s]==4557430888798830399) RET(-1);
    RET(dis[s]);
}


//Be Name Khoda
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma optimize O3
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); }
#define MKP make_pair
#define RETD(x) { cout << fixed << setprecision(15) << x; exit(0); }
#define GEI(x) scanf("%d",&x)
#define GEL(x) scanf("%lld",&x)
#define ALL(x) x.begin(),x.end()
const ll M=4e5+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;

vll h[M];
ll cnt[M];
ll dis[M];
ll ss[M];
ll n,m;
ll s,t;
vll v;
ll qu[M],qh,qt;
int main()
{
	GEL(n);GEL(m);
    For(i,0,m)
    {
        ll u,v;
        GEL(u);GEL(v);
        u--;v--;
        h[v].PB(u);
        cnt[u]++;
    }
    GEL(s);GEL(t);
    s--;t--;
    memset(dis,63,sizeof dis);
    v.PB(t);
    For(i,0,n)
    {
        qh=qt=0;
        for (ll x:v)
        {
            qu[qh++]=x;
        }
        while (qh!=qt)
        {
            ll f=qu[qt++];
            ss[f]++;
            dis[f]=i;
            for (ll y:h[f])
            {
                cnt[y]--;
                if (!cnt[y])
                    qu[qh++]=y;
            }
        }
        v.clear();
        For(j,0,qh)
        {
            for (ll y:h[qu[j]])
            {
                if (dis[y]>i)
                {
                    cnt[y]=0;
                    dis[y]=i;
                    v.PB(y);
                }
            }
        }
    }
    /*For(i,0,n)
    {
        ER(i);
        ER(cnt[i]);
        ER(ss[i]);
        ER(dis[i]);
    }//*/
    RET(dis[s]);
}


//Be Name Khoda
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma optimize O3
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); }
#define MKP make_pair
#define RETD(x) { cout << fixed << setprecision(15) << x; exit(0); }
#define GEI(x) scanf("%d",&x)
#define GEL(x) scanf("%lld",&x)
#define ALL(x) x.begin(),x.end()
const ll M=2e6+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;

vll h[M];
ll cnt[M];
ll dis[M];
ll ss[M];
ll n,m;
ll s,t;
vll v;
ll qu[M],qh,qt;
int main()
{
	GEL(n);GEL(m);
    For(i,0,m)
    {
        ll u,v;
        GEL(u);GEL(v);
        u--;v--;
        h[v].PB(u);
        cnt[u]++;
    }
    GEL(s);GEL(t);
    s--;t--;
    memset(dis,63,sizeof dis);
    v.PB(t);
    For(i,0,n)
    {
        qh=qt=0;
        for (ll x:v)
        {
            qu[qh++]=x;
        }
        while (qh!=qt)
        {
            ll f=qu[qt++];
            ss[f]++;
            dis[f]=i;
            for (ll y:h[f])
            {
                cnt[y]--;
                if (!cnt[y])
                    qu[qh++]=y;
            }
        }
        v.clear();
        For(j,0,qh)
        {
            for (ll y:h[qu[j]])
            {
                if (dis[y]>i)
                {
                    cnt[y]=0;
                    dis[y]=i;
                    v.PB(y);
                }
            }
        }
    }
    /*For(i,0,n)
    {
        ER(i);
        ER(cnt[i]);
        ER(ss[i]);
        ER(dis[i]);
    }//*/
    if (dis[s]==4557430888798830399) RET(-1);
    RET(dis[s]);
}


//Be Name Khoda
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma optimize O3
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); }
#define MKP make_pair
#define RETD(x) { cout << fixed << setprecision(15) << x; exit(0); }
#define GEI(x) scanf("%d",&x)
#define GEL(x) scanf("%lld",&x)
#define ALL(x) x.begin(),x.end()
const ll M=4e5+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;

vll h[M];
ll cnt[M];
ll dis[M];
ll n,m;
ll s,t;
vll v;
ll qu[M],qh,qt;
int main()
{
	GEL(n);GEL(m);
    For(i,0,m)
    {
        ll u,v;
        GEL(u);GEL(v);
        u--;v--;
        h[v].PB(u);
        cnt[u]++;
    }
    GEL(s);GEL(t);
    s--;t--;
    memset(dis,63,sizeof dis);
    v.PB(t);
    For(i,0,n)
    {
        qh=qt=0;
        for (ll x:v)
        {
            qu[qh++]=x;
        }
        while (qh!=qt)
        {
            ll f=qu[qt++];
            dis[f]=i;
            for (ll y:h[f])
            {
                cnt[y]--;
                if (!cnt[y])
                    qu[qh++]=y;
            }
        }
        v.clear();
        For(j,0,qh)
        {
            for (ll y:h[j])
            {
                if (dis[y]>i)
                {
                    v.PB(y);
                }
            }
        }
    }
    RET(dis[s]);
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 1e6 + 5;

int N, M, s, t;
vector<int> adj[maxn];
int out[maxn];
int dist[maxn];

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N >> M;
  while(M--){
    int u, v; cin >> u >> v;
    adj[v].eb(u);
    out[u]++;
  }
  cin >> s >> t;
  deque<int> dq;
  memset(dist, -1, sizeof dist);
  dist[t] = 0;
  dq.pb(t);
  while(dq.size()){
    int u = dq.front(); dq.pop_front();
    if(u == s) break;
    for(int v : adj[u]){
      out[v]--;
      if(out[v] == 0){
        if(dist[v] == -1 || dist[v] > dist[u]){
          dist[v] = dist[u];
          dq.push_front(v);
        }
      }
      else{
        if(dist[v] == -1 || dist[v] > dist[u] + 1){
          dist[v] = dist[u] + 1;
          dq.push_back(v);
        }
      }
    }
  }
  cout << dist[s];
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 1e6 + 5;

int N, M, s, t;
vector<int> adj[maxn];
int out[maxn];
int dist[maxn];
bool vis[maxn];

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N >> M;
  while(M--){
    int u, v; cin >> u >> v;
    adj[v].eb(u);
    out[u]++;
  }
  cin >> s >> t;
  deque<int> dq;
  memset(dist, -1, sizeof dist);
  dist[t] = 0;
  dq.pb(t);
  while(dq.size()){
    int u = dq.front(); dq.pop_front();
    if(u == s) break;
    if(vis[u]) continue;
    vis[u] = true;
    for(int v : adj[u]){
      out[v]--;
      if(out[v] == 0){
        if(dist[v] == -1 || dist[v] > dist[u]){
          dist[v] = dist[u];
          dq.push_front(v);
        }
      }
      else{
        if(dist[v] == -1 || dist[v] > dist[u] + 1){
          dist[v] = dist[u] + 1;
          dq.push_back(v);
        }
      }
    }
  }
  cout << dist[s];
}


#include<bits/stdc++.h>
#define int long long
#define ll long long
#define maxN 1000005
#define rep(i,n) for(int i=0;i<n;i++)
#define refv(i,l,r) for(int i=l;i<r;i++)
#define rerv(i,l,r) for(int i=l;i>=r;i--)
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll> >
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define printvector(v) for(int i= 0;i<v.size();i++) {cout<<v[i]<<" ";} cout<<endl;
#define printset(s) for(auto it = s.begin();it!=S.end();it++){cout<<*it<<" ";} cout<<endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int32_t main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fastio;
    int n,m;
    cin>>n>>m;
    vector<int> g[n+1],v[n+1];
    int out[n+1]={0};
    rep(i,m)
    {
        int x,y;
        cin>>x>>y;
       // g[x].pb(y);
        v[y].pb(x);
        out[x]++;
    }
    int src,des;
    cin>>src>>des;
    int ans[n+1];
    memset(ans,-1,sizeof(ans));
    ans[des]=0;
    deque<int> de;
    de.push_front(des);
    int vis[n+1]={0};
    while(!de.empty())
    {
        int node=de.front();
        de.pop_front();
        if(node==src)break;
        if(vis[node])
        {
            continue;
        }
        vis[node]=1;
        for(auto x: v[node])
        {
            --out[x];
            if(out[x]==0)
            {
                if(ans[node]<ans[x] || ans[x]==-1)
                {ans[x]=ans[node];
                de.push_front(x);
            }}
            else
            {
                if(ans[x]==-1)
                {ans[x]=ans[node]+1;
                de.push_back(x);
            }}
        }
    }
    cout<<ans[src]<<endl;
}


#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define DEBUG_CAT
#ifdef DEBUG_CAT

#define dbg(...)   printf( __VA_ARGS__ )
#else
#define dbg(...)   /****nothing****/
#endif
static char stdinBuffer[1024];
static char* stdinDataEnd = stdinBuffer + sizeof (stdinBuffer);
static const char* stdinPos = stdinDataEnd;

void readAhead(size_t amount)
{
    size_t remaining = stdinDataEnd - stdinPos;
    if (remaining < amount) {
       memmove(stdinBuffer, stdinPos, remaining);
       size_t sz = fread(stdinBuffer + remaining, 1, sizeof (stdinBuffer) - remaining, stdin);
       stdinPos = stdinBuffer;
       stdinDataEnd = stdinBuffer + remaining + sz;
       if (stdinDataEnd != stdinBuffer + sizeof (stdinBuffer))
         *stdinDataEnd = 0;
    }
}

int rint()
{
    readAhead(16);

    int x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}
char rch()
{
    readAhead(16);
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    char ans=*stdinPos;
    ++stdinPos;
    return ans;
}
long long rlong()
{
    readAhead(32);

    long long x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}
queue<int> vlive[2];
const int mn=2e6+4;
vector<int> rg[mn];
int outdeg[mn];
int vmore[mn];
bool seen[mn];
bool tseen[mn];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
  int n=rint(),m=rint();
  for (int i=0;i<m;i++) {
    int x=rint(),y=rint();
    //printf("%d->%d\n",y,x);
    rg[y].PB(x);
    outdeg[x]++;
  }
  int s=rint(),t=rint();
  int cur=0,nxt=1;
  vlive[cur].push(t);
  for (int cost=0;;cost++) {
    if (vlive[cur].size()==0) {
      printf("-1\n"); return 0;
    }
    queue<int> &q=vlive[cur];
    int morecnt=0;
    while(!q.empty()) {
      int x=q.front();
      if (x==s) {
        printf("%d\n",cost); return 0;
      }
      q.pop();
      if (seen[x]) continue;
      //printf("cost:%d x:%d\n",cost,x);
      seen[x]=true;
      vmore[morecnt++]=x;
      for (auto &y:rg[x]) {
        --outdeg[y];
        //printf("y:%d deg:%d\n",y,outdeg[y]);
        if (outdeg[y]==0) {
          q.push(y);
        }
      }
    }
    queue<int> &nq=vlive[nxt];
    nq=queue<int>();
    for (int i=0;i<morecnt;i++) {
      int x=vmore[i];
      for (auto &y:rg[x]) {
        if (!seen[y]&&!tseen[y]) {
          //printf("cost:%d y:%d\n",cost,y);
          tseen[y]=true;
          nq.push(y);
        }
      }
    }
    swap(cur,nxt);
  }
}


#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define DEBUG_CAT
#ifdef DEBUG_CAT

#define dbg(...)   printf( __VA_ARGS__ )
#else
#define dbg(...)   /****nothing****/
#endif
static char stdinBuffer[1024];
static char* stdinDataEnd = stdinBuffer + sizeof (stdinBuffer);
static const char* stdinPos = stdinDataEnd;

void readAhead(size_t amount)
{
    size_t remaining = stdinDataEnd - stdinPos;
    if (remaining < amount) {
       memmove(stdinBuffer, stdinPos, remaining);
       size_t sz = fread(stdinBuffer + remaining, 1, sizeof (stdinBuffer) - remaining, stdin);
       stdinPos = stdinBuffer;
       stdinDataEnd = stdinBuffer + remaining + sz;
       if (stdinDataEnd != stdinBuffer + sizeof (stdinBuffer))
         *stdinDataEnd = 0;
    }
}

int rint()
{
    readAhead(16);

    int x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}
char rch()
{
    readAhead(16);
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    char ans=*stdinPos;
    ++stdinPos;
    return ans;
}
long long rlong()
{
    readAhead(32);

    long long x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}
queue<int> vlive[2];
const int mn=1e6+2;
vector<int> rg[mn];
int outdeg[mn];
int vmore[mn];
bool seen[mn];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
  int n=rint(),m=rint();
  for (int i=0;i<m;i++) {
    int x=rint(),y=rint();
    rg[y].PB(x);
    outdeg[x]++;
  }
  int s=rint(),t=rint();
  if (s==t) {printf("0\n"); return 0;}
  int cur=0,nxt=1;
  vlive[cur].push(t);
  seen[t]=true;
  for (int cost=0;;cost++) {
    if (vlive[cur].size()==0) {
      printf("-1\n"); return 0;
    }
    queue<int> &q=vlive[cur];
    int morecnt=0;
    while(!q.empty()) {
      int x=q.front();
      //printf("cost:%d x:%d\n",cost,x);
      if (x==s) {
        printf("%d\n",cost); return 0;
      }
      q.pop();
      seen[x]=true;
      vmore[morecnt++]=x;
      for (auto &y:rg[x]) {
        --outdeg[y];
        //printf("y:%d outdeg:%d\n",y,outdeg[y]);
        if (outdeg[y]==0) {
          q.push(y);
        }
      }
    }
    queue<int> &nq=vlive[nxt];
    nq=queue<int>();
    for (int i=0;i<morecnt;i++) {
      int x=vmore[i];
      for (auto &y:rg[x]) {
        if (!seen[y]) {
          seen[y]=true;
          //printf("cost:%d y:%d\n",cost,y);
          nq.push(y);
        }
      }
    }
    swap(cur,nxt);
  }
}


#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define DEBUG_CAT
#ifdef DEBUG_CAT

#define dbg(...)   printf( __VA_ARGS__ )
#else
#define dbg(...)   /****nothing****/
#endif
static char stdinBuffer[1024];
static char* stdinDataEnd = stdinBuffer + sizeof (stdinBuffer);
static const char* stdinPos = stdinDataEnd;

void readAhead(size_t amount)
{
    size_t remaining = stdinDataEnd - stdinPos;
    if (remaining < amount) {
       memmove(stdinBuffer, stdinPos, remaining);
       size_t sz = fread(stdinBuffer + remaining, 1, sizeof (stdinBuffer) - remaining, stdin);
       stdinPos = stdinBuffer;
       stdinDataEnd = stdinBuffer + remaining + sz;
       if (stdinDataEnd != stdinBuffer + sizeof (stdinBuffer))
         *stdinDataEnd = 0;
    }
}

int rint()
{
    readAhead(16);

    int x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}
char rch()
{
    readAhead(16);
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    char ans=*stdinPos;
    ++stdinPos;
    return ans;
}
long long rlong()
{
    readAhead(32);

    long long x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}
queue<int> vlive[2];
const int mn=2e6+4;
vector<int> rg[mn];
int outdeg[mn];
int vmore[mn];
bool seen[mn];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
  int n=rint(),m=rint();
  for (int i=0;i<m;i++) {
    int x=rint(),y=rint();
    rg[y].PB(x);
    outdeg[x]++;
  }
  int s=rint(),t=rint();
  int cur=0,nxt=1;
  vlive[cur].push(t);
  seen[t]=true;
  for (int cost=0;;cost++) {
    if (vlive[cur].size()==0) {
      printf("-1\n"); return 0;
    }
    queue<int> &q=vlive[cur];
    int morecnt=0;
    while(!q.empty()) {
      int x=q.front();
      if (x==s) {
        printf("%d\n",cost); return 0;
      }
      q.pop();
      seen[x]=true;
      vmore[morecnt++]=x;
      for (auto &y:rg[x]) {
        --outdeg[y];
        if (outdeg[y]==0) {
          q.push(y);
        }
      }
    }
    queue<int> &nq=vlive[nxt];
    nq=queue<int>();
    for (int i=0;i<morecnt;i++) {
      int x=vmore[i];
      for (auto &y:rg[x]) {
        if (!seen[y]) {
          seen[y]=true;
          nq.push(y);
        }
      }
    }
    swap(cur,nxt);
  }
}


#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define DEBUG_CAT
#ifdef DEBUG_CAT

#define dbg(...)   printf( __VA_ARGS__ )
#else
#define dbg(...)   /****nothing****/
#endif
static char stdinBuffer[1024];
static char* stdinDataEnd = stdinBuffer + sizeof (stdinBuffer);
static const char* stdinPos = stdinDataEnd;

void readAhead(size_t amount)
{
    size_t remaining = stdinDataEnd - stdinPos;
    if (remaining < amount) {
       memmove(stdinBuffer, stdinPos, remaining);
       size_t sz = fread(stdinBuffer + remaining, 1, sizeof (stdinBuffer) - remaining, stdin);
       stdinPos = stdinBuffer;
       stdinDataEnd = stdinBuffer + remaining + sz;
       if (stdinDataEnd != stdinBuffer + sizeof (stdinBuffer))
         *stdinDataEnd = 0;
    }
}

int rint()
{
    readAhead(16);

    int x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}
char rch()
{
    readAhead(16);
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    char ans=*stdinPos;
    ++stdinPos;
    return ans;
}
long long rlong()
{
    readAhead(32);

    long long x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}
queue<int> vlive[2];
const int mn=2e6+4;
vector<int> rg[mn];
int outdeg[mn];
int vmore[mn];
bool seen[mn];
bool tseen[mn];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
  int n=rint(),m=rint();
  for (int i=0;i<m;i++) {
    int x=rint(),y=rint();
    //printf("%d->%d\n",y,x);
    rg[y].PB(x);
    outdeg[x]++;
  }
  int s=rint(),t=rint();
  int cur=0,nxt=1;
  vlive[cur].push(t);
  for (int cost=0;;cost++) {
    if (vlive[cur].size()==0) {
      printf("-1\n"); return 0;
    }
    queue<int> &q=vlive[cur];
    int morecnt=0;
    while(!q.empty()) {
      int x=q.front();
      if (x==s) {
        printf("%d\n",cost); return 0;
      }
      q.pop();
      if (seen[x]) continue;
      //printf("cost:%d x:%d\n",cost,x);
      seen[x]=true;
      vmore[morecnt++]=x;
      for (auto &y:rg[x]) {
      	if (seen[y]) continue;
        --outdeg[y];
        //printf("y:%d deg:%d\n",y,outdeg[y]);
        if (outdeg[y]==0) {
          q.push(y);
        }
      }
    }
    queue<int> &nq=vlive[nxt];
    nq=queue<int>();
    for (int i=0;i<morecnt;i++) {
      int x=vmore[i];
      for (auto &y:rg[x]) {
        if (!seen[y]&&!tseen[y]) {
          //printf("cost:%d y:%d\n",cost,y);
          tseen[y]=true;
          nq.push(y);
        }
      }
    }
    swap(cur,nxt);
  }
}


#include <bits/stdc++.h>
using namespace std ;

const int MAXN = 1e6 + 100 ;
vector<int> in[MAXN] ;
int out[MAXN] , dp[MAXN] ;
int32_t main(){
	ios_base::sync_with_stdio(0) ;
	cin . tie(0) ; cout . tie(0) ;
	int n , m ; cin >> n >> m ;
	for(int i = 0 ; i < m ; i ++){
		int x , y ; cin >> x >> y ;
		x -- , y -- ;
		in[y] . push_back(x) ;
		out[x] ++ ;
	}
	set<pair<int , int>> st ;
	int s , t ; cin >> s >> t ;
	s -- ; t -- ;
	st . insert({0 , t}) ;
	memset(dp , 63 , sizeof dp) ;
	dp[t] = 0 ;
	while(st . size()){
		int v = st . begin() -> second ; st . erase(st . begin()) ;
		for(auto u : in[v]){
			out[u] -- ;
			if((dp[v] + bool(out[u])) < dp[u]){
				st . erase({dp[u] , u}) ;
				dp[u] = (dp[v] + bool(out[u])) ;
				st . insert({dp[u] , u}) ;
			}
		}
	}
	cout << (dp[s] > n ? -1 : dp[s]) << '\n' ;
}


/*input
4 5
1 2
2 1
1 3
2 4
3 4
1 4
*/
#include<iostream>
#include<vector>
#include<limits>
#include<limits.h>
#include<string>
#include<iterator>
#include<deque>
#include<queue>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<stack>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#include<stdio.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m,u,v,so,ter;
	cin>>n>>m;
	vector<int> outDeg(n+1,0),DP(n+1,INT_MAX),visited(n+1,0);
	vector<vector<int>> graph(n+1);
	for(int i;i<m;i++)
	{
		cin>>u>>v;
		graph[v].push_back(u);
		outDeg[u]++;
	}
	cin>>so>>ter;
	DP[ter]=0;
	deque<int> dq;
	dq.push_back(ter);
	while(!dq.empty())
	{
		v=dq.front();
		dq.pop_front();
		if(visited[v])
			continue;
		visited[v]=1;
		for(auto it: graph[v])
		{
			outDeg[it]--;
			if(outDeg[it]==0 && DP[it]>DP[v])
			{
				DP[it]=DP[v];
				dq.push_front(it);
			}
			if(outDeg[it]>0 && DP[it]>(DP[v]+1))
			{
				DP[it]=DP[v]+1;
				dq.push_back(it);
			}
		}
	}
	// for(auto it:DP)
	// 	cout<<it<<" "<<" ";
	// cout<<"\n"<<so<<" "<<ter<<"\n";
	if(DP[so]==INT_MAX)
		cout<<"-1\n";
	else
		cout<<DP[so]<<"\n";
}