def main():

	v, e, *L = list(map(int, open(0).read().split()))

	g = [[] for _ in range(v)]

	deg = [0] * v

	for s, t in zip(*[iter(L)] * 2):

		g[s - 1].append(t - 1)

		deg[t - 1] += 1

	q = []

	for i, d in enumerate(deg):

		if not d:

			q.append(i)

	ans = [0] * v

	while q:

		c = q.pop(0)

		for n in g[c]:

			deg[n] -= 1

			if not deg[n]:

				q.append(n)

				ans[n] = c + 1

	print(("\n".join(map(str, ans))))



if __name__ == "__main__":

	main()
from collections import*



def main():

	v, e, *L = list(map(int, open(0).read().split()))

	g = [[] for _ in range(v)]

	deg = [0] * v

	for s, t in zip(*[iter(L)] * 2):

		g[s - 1].append(t - 1)

		deg[t - 1] += 1

	q = deque()

	for i, d in enumerate(deg):

		if not d:

			q.append(i)

	ans = [0] * v

	while q:

		c = q.popleft()

		for n in g[c]:

			deg[n] -= 1

			if not deg[n]:

				q.append(n)

				ans[n] = c + 1

	print(("\n".join(map(str, ans))))



if __name__ == "__main__":

	main()
def main():
    v, e, *L = list(map(int, open(0).read().split()))
    g = [[] for _ in range(v)]
    deg = [0] * v
    for s, t in zip(*[iter(L)] * 2):
        g[s - 1].append(t - 1)
        deg[t - 1] += 1
    q = []
    for i, d in enumerate(deg):
        if not d:
            q.append(i)
    ans = [0] * v
    while q:
        c = q.pop(0)
        for n in g[c]:
            deg[n] -= 1
            if not deg[n]:
                q.append(n)
                ans[n] = c + 1
    print(("\n".join(map(str, ans))))


if __name__ == "__main__":
    main()

from collections import *


def main():
    v, e, *L = list(map(int, open(0).read().split()))
    g = [[] for _ in range(v)]
    deg = [0] * v
    for s, t in zip(*[iter(L)] * 2):
        g[s - 1].append(t - 1)
        deg[t - 1] += 1
    q = deque()
    for i, d in enumerate(deg):
        if not d:
            q.append(i)
    ans = [0] * v
    while q:
        c = q.popleft()
        for n in g[c]:
            deg[n] -= 1
            if not deg[n]:
                q.append(n)
                ans[n] = c + 1
    print(("\n".join(map(str, ans))))


if __name__ == "__main__":
    main()

+from collections import * + + -    q = [] +    q = deque() -        c = q.pop(0) +        c = q.popleft()