def dot(mtr0,mtr1): a,b=len(mtr0),len(mtr1[0]) t=len(mtr0[0]) if t!=len(mtr1):return None ret=[[0]*b for _ in range(a)] for i in range(a): for j in range(b): tmp=0 for k in range(t): tmp+=mtr0[i][k]*mtr1[k][j] if tmp>0:tmp=1 ret[i][j]=tmp return ret def main0(n,m,t,ab): # ダブリング。O(n^2) g=[[0]*n for _ in range(n)] for a,b in ab: g[b][a]=1 vc=[[0] for _ in range(n)] vc[0][0]=1 while t: if t%2==1:vc=dot(g,vc) g=dot(g,g) t>>=1 ans=0 for i in range(n): if vc[i][0]==1: ans+=1 return ans if __name__=='__main__': n,m,t=map(int,input().split()) ab=[list(map(int,input().split())) for _ in range(m)] ret0=main0(n,m,t,ab) print(ret0)