import numpy as np def pow_matrix_mod(x, n): if not n: return np.eye(len(x), dtype=int) if n % 2 == 0: return pow_matrix_mod(np.where((x @ x) != 0, 1, 0), n // 2) else: tmp = pow_matrix_mod(np.where((x @ x) != 0, 1, 0), (n - 1) // 2) return np.where((x @ tmp) != 0, 1, 0) N, M, T = map(int, input().split()) matr = [[0] * N for _ in range(N)] for _ in range(M): a, b = map(int, input().split()) matr[a][b] = 1 matr = np.array(matr) first = np.zeros(N, dtype=int) first[0] = 1 ans = np.count_nonzero(first @ pow_matrix_mod(matr, T)) print(ans)