n,m,t = map(int,input().split()) e = [[] for i in range(n)] db = [[set() for j in range(60)] for i in range(n)] for i in range(m): a,b = map(int,input().split()) db[a][0].add(b) for i in range(1,60): for j in range(n): for k in db[j][i-1]: db[j][i] |= db[k][i-1] ans = set([0]) for i in range(60): if t >> i & 1: nex = set() for j in ans: nex |= db[j][i] ans = nex print(len(ans))