(n, m, t) = map(int,input().split()) #行列の積 def mul(a, b): c = [[0 for j in range(n)] for i in range(n)] for i in range(n): for j in range(n): for k in range(n): c[i][j] |= a[i][k] & b[k][j] return c #有向グラフを行列に置き換える G = [[0 for j in range(n)] for i in range(n)] for i in range(m): (a, b) = map(int,input().split()) G[b][a] = 1 # A = G ** T A = [[0 for j in range(n)] for i in range(n)] for i in range(n): A[i][i] = 1 while t: if t % 2 == 1: A = mul(A, G) G = mul(G, G) t = t // 2 #answer ans = 0 for i in range(n): ans += A[i][0] if ans == 0: print(-1) else: print(ans)