diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -9,7 +9,7 @@
 for i in range(M):
     U[i], V[i] = map(int, input().split())
     relations[V[i] - 1].append(U[i] - 1)
-    cnt[V[i] - 1] += 1
+    cnt[U[i] - 1] += 1
 for i in range(N):
     if cnt[i] == 0:
         queue.append(i)
