mod = 998244853 def mat_mul(a, b): n = len(a) res = [[0] * n for i 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] res[i][j] %= mod return res def mat_pow(a, k): if k == 1: return a n = len(a) res = [[0] * n for i in range(n)] for i in range(n): res[i][i] = 1 while k: if k & 1: res = mat_mul(res, a) a = mat_mul(a, a) k >>= 1 return res n, m, t = map(int, input().split()) G = [[0] * n for i in range(n)] for _ in range(m): a, b = map(int, input().split()) G[a][b] = 1 G2 = mat_pow(G, t) ans = 0 for i in range(n): if G2[0][i] > 0: ans += 1 print(ans)