N, M, T = map(int, input().split()) links = [[] for _ in range(N)] for _ in range(M): a, b = map(int, input().split()) links[a].append(b) s = {0} for _ in range(T): t = set() for i in s: for j in links[i]: t.add(j) s = t print(len(s))