import sys input = sys.stdin.buffer.readline # nxnの行列積 # n is necessary def matrix_product(A, B): res = [[0] * n for _ in range(n)] for i in range(n): for k in range(n): for j in range(n): res[i][j] += A[i][k] * B[k][j] if res[i][j]: res[i][j] = 1 return res def matrix_exponents(A, t): res = [[0] * n for _ in range(n)] for i in range(n): res[i][i] = 1 while t > 0: if t & 1 == 1: res = matrix_product(res, A) A = matrix_product(A, A) t //= 2 return res n, m, t = map(int, input().split()) graph = [[0] * (n) for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) a, b = a - 1, b - 1 graph[a][b] = 1 res = matrix_exponents(graph, t) ans = 0 for j in range(n): if res[j][0]: ans += 1 print(ans)