def m(a,b): r=[[0]*len(b[0]) for i in range(len(a))] for i in range(len(a)): for k in range(len(b)): for j in range(len(b[0])): r[i][j]|=(a[i][k]&b[k][j]) return r def p(a,n): r=[[0]*len(a) for i in range(len(a))] b=[] for i in range(len(a)): r[i][i]=1 b.append(a[i][:]) l=n while l>0: if l&1: r=m(b,r) b=m(b,b) l>>=1 return r N,M,T=map(int,input().split()) A=[[0]*N for i in range(N)] for i in range(M): a,b=map(int,input().split()) A[a-1][b-1]=1 B=[[0]*N for i in range(N)] B[0][N-1]=1 C=m(p(A,T),B) print(sum([C[i][-1] for i in range(N)]))