INF = 10 ** 19 n, m, t = map(int, input().split()) mat = [[INF] * n for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) mat[a - 1][b - 1] = 1 res = [[INF] * n for _ in range(n)] for i in range(n): res[i][i] = 0 while t > 0: if t & 1: tmp = [[INF] * n for _ in range(n)] for i in range(n): for j in range(n): for k in range(n): tmp[i][j] = min(tmp[i][j], res[i][k] + mat[k][j]) res = [row[:] for row in tmp] tmp = [[INF] * n for _ in range(n)] for i in range(n): for j in range(n): for k in range(n): tmp[i][j] = min(tmp[i][j], mat[i][k] + mat[k][j]) mat = [row[:] for row in tmp] t //= 2 ans = 0 for i in range(n): if res[0][i] < INF: ans += 1 print(ans)